鉴于以下ASP.NET WebAPI,我尝试使用fiddler发送测试POST,但无法使其工作.无论发送什么,我总是只看到无数据发送到服务消息.
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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。