webapi post请求返回Null异常

Cha*_*aru 5 c# asp.net-web-api

我在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;
    }
}
Run Code Online (Sandbox Code Playgroud)

发送来自Fiddler的帖子请求:

User-Agent: Fiddler
Host: localhost:11033
Content-Length: 1852
Content-Type: text/xml

Body:
<customer>
<customer_id>1234</customer_id>
</customer>
Run Code Online (Sandbox Code Playgroud)

Global.asax中

GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;
Run Code Online (Sandbox Code Playgroud)