How do I get request parameters using RestSharp to Asp.Net.Core?

  • Thread starter Thread starter j4ck50nD
  • Start date Start date
J

j4ck50nD

Guest
The request (in a WPF Net.Fx.4 project)


var client = new RestClient(_serviceAddress);

var request = new RestRequest("SignIn", Method.POST);

request.RequestFormat = DataFormat.Json;
request.AddJsonBody(new { UserName = userName, Password = password });
//request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
var response = client.Execute(request);

My Api (in a Asp.Net.Core.2.2 project)


public JsonResult SignIn([FromBody]string UserName, [FromBody]string Password)
{
return new JsonResult(new { result = "fail", message = "hello"});//this gets called but params always null
}


In my API, which does get invoked, the values are always `null`, what am I doing wrong?

https://localhost:44372/api/signin

I've tried all manner of decorations on the parameters and even none.

I've also tried various connotations on the `request.Add...` I've tried `AddXmlBody` I've tried adding a header `ContentType` nothing works. I've tried loads of exampled from here and still no joy.

If I am doing this wrong do please let me know, thanks :)
DJack10

Continue reading...
 
Back
Top