如何使用Fiddler将XML发布到ASP.NET WebAPI
发布时间:2020-12-16 22:58:23 所属栏目:百科 来源:网络整理
导读:鉴于以下ASP.NET WebAPI,我尝试使用Fiddler发送测试POST,但无法使其工作.无论发送什么,我总是只看到无数据发送到服务消息. Imports System.Web.HttpImports System.Net.HttpImports System.NetNamespace HelloWebApiDemo Public Class MyApiController Inher
鉴于以下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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |