我在这里检查了类似的问题:
web-api POST body object always null
这与我的场景中发生的情况并不完全一致 . 我正在使用以下请求标头内容类型向我的api发出请求:
Key Value
Content-Type application/x-www-form-urlencoded
我的请求主体是我从其他服务获得的响应,我无法更改
Response=SomeLongStringOfBAse64EncodedData
我可以看到的我的Api Post方法通过在其上设置断点来实现:
public HttpResponseMessage Authenticate([FromBody]string Response)
但是,响应字符串总是变为空值,即使我在请求正文中看到它,我无法理解 .
1 回答
对于像这样的动作方法
public HttpResponseMessage Authenticate([FromBody]string Response)
,你需要像这样的请求体,绑定工作 .
=SomeLongStringOfBAse64EncodedData
如果要绑定
Response=SomeLongStringOfBAse64EncodedData
,则需要更改此操作方法 .public HttpResponseMessage Authenticate(SomeClass response)
并添加一个类