【发布时间】:2019-09-30 18:54:56
【问题描述】:
我正在尝试通过 web api microsoft 应用程序中的 post 请求传递对象的参数,但传递的参数始终为 null。
这是我的post方法的控制器,在调试中程序到达了方法但是dataUrlIN.url字符串总是空的
[HttpPost]
public void Post(DataUrl dataUrlIN)
{
string a = dataUrlIN.url;
a += a + "/test";
}
这是DataUrl的对象
public class DataUrl
{
public string url { get; set; }
}
这是发帖请求
POST /api/values HTTP/1.1
Host: localhost:50673
Content-Type: application/json
User-Agent: PostmanRuntime/7.11.0
Accept: */*
Cache-Control: no-cache
Postman-Token: a12b47ba-8595-4297-b3e1-380052fb2a46,b4b4d699-206b-47ff-9fa3-71d06d4334d2
Host: localhost:50673
accept-encoding: gzip, deflate
content-length: 28
Connection: keep-alive
cache-control: no-cache
{
"url" : "helloWorld"
}
发送post请求后,public void Post(Data Url dataUrlIN)方法中的断点被触发,但url字符串为空“HelloWorld”字符串永远不会出现
【问题讨论】:
-
在参数中添加[FromBody]
标签: c# asp.net-web-api