请求(在WPF Net.Fx.4项目中)
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);
我的Api(在Asp.Net.Core.2.2项目中)
public JsonResult SignIn([FromBody]string UserName, [FromBody]string Password)
{
return new JsonResult(new { result = "fail", message = "hello"});//this gets called but params always null
}
在我的API(确实会被调用)中,值始终为null
,我在做什么错了?
https://localhost:44372/api/signin
我尝试了各种形式的参数修饰,甚至没有修饰。
我还尝试过request.Add...
的各种涵义,尝试过AddXmlBody
,尝试添加标头ContentType
无效。我从这里尝试过许多示例,但仍然没有乐趣。
如果我做错了,请告诉我,谢谢:)