鉴于以下ASP.NET WebAPI,我尝试使用Fiddler发送测试POST,但无法使其工作.无论发送什么,我总是只看到无数据发送到服务消息. Imports System.Web.HttpImports System.Net.HttpImports System.NetNamespace HelloWebA
Imports System.Web.Http Imports System.Net.Http Imports System.Net Namespace HelloWebApiDemo Public Class MyApiController Inherits ApiController Public Function [Get]() As HttpResponseMessage Return Request.CreateResponse(HttpStatusCode.OK, "Hello") End Function Public Class MyXmlData Public Property UserName As String Public Property Password As String Public Property SomeData As String End Class Public Function Post(<FromBody> x As MyXmlData) As HttpResponseMessage If x Is Nothing Then Return Request.CreateResponse(HttpStatusCode.InternalServerError, "No data sent to service") End If Dim u As String = String.Empty Dim p As String = String.Empty Dim d As String = String.Empty If Not String.IsNullOrEmpty(x.UserName) Then u = x.UserName End If If Not String.IsNullOrEmpty(x.Password) Then p = x.Password End If If Not String.IsNullOrEmpty(x.SomeData) Then d = x.SomeData End If Return Request.CreateResponse(HttpStatusCode.OK, String.Format("You posted {0}, {1} with a string that is {2} characters in length", u, p, d.Length.ToString)) End Function End Class End Namespace
在Fiddler,我的POST看起来像这样:
任何人都可以告诉我我做错了什么?我使用Content-Type:text / xml希望ASP.NET能够正确解密它.
更新
新屏幕抓取输入:
保留Content-Type:text / xml请求标头并将XML更改为这样.<MyApiController.MyXmlData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/HelloWebApiDemo.HelloWebApiDemo"> <Password>somepassword</Password> <SomeData>somedata</SomeData> <UserName>bob</UserName> </MyApiController.MyXmlData>