我在Web API控制器中有一个简单的post方法,它接受HttpRequestMessage
。不知何故,XML没有被解析为HttpRequestMessage
。我已将应用配置为使用XmlSerializer
尝试将简单的XML传递给它但给我Null引用异常
public class SyncSubscriptionController : ApiController
{
[HttpPost]
public HttpResponseMessage Post(HttpRequestMessage req)
{
var data = req.Content.ReadAsStringAsync().Result;
}
}
从Fiddler发送帖子请求:
User-Agent: Fiddler
Host: localhost:11033
Content-Length: 1852
Content-Type: text/xml
Body:
<customer>
<customer_id>1234</customer_id>
</customer>
Global.asax中
GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;