gpt4 book ai didi

asp.net - 如何使用 Fiddler 将 XML POST 到 ASP.NET WebAPI

转载 作者:行者123 更新时间:2023-12-05 01:07:04 24 4
gpt4 key购买 nike

鉴于以下 ASP.NET WebAPI,我正在尝试使用 Fiddler 发送测试 POST,但无法使其正常工作。无论我发送什么,我总是只看到 No data sent to service 消息。

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 如下所示:

enter image description here

任何人都可以就我做错了什么提出建议吗?我用过 Content-Type: text/xml希望 ASP.NET 能够正确地破译它。

更新

新屏幕抓取以下输入:

enter image description here

最佳答案

保留 Content-Type: text/xml请求 header 并将 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>

关于asp.net - 如何使用 Fiddler 将 XML POST 到 ASP.NET WebAPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19052280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com