【问题标题】:RESTSharp empty body on ExecuteAsyncPost versus ExecutePostExecuteAsyncPost 与 ExecutePost 上的 RESTSharp 空正文
【发布时间】:2013-03-18 02:48:31
【问题描述】:

我正在使用 RestSharp 构建对我的 MVC 入口点的 Rest 访问(实际上是为了从 monotouch 中使用它们,但现在我正在 Windows 7、vs2010、.net 4、RestSharp 104.1 上进行测试)

如果我创建一个请求并调用

client.ExecuteAsPost<Model.Client>( request );

它有效,我可以在 fiddler 中看到原始数据包

POST http://localhost.:49165/Services/Client/ClientAdminService/FindClient HTTP/1.1 
Timestamp: Monday, March 18, 2013 1:56:02 AM 
X-PS-Authentication: YADAYADA:<deleted for brevity>== 
Accept: application/xml 
User-Agent: RestSharp 104.1.0.0 
Content-Type: application/xml; charset=utf-8 
Host: localhost.:49165 
Content-Length: 256 
Accept-Encoding: gzip, deflate 
Connection: Keep-Alive


<Client xmlns="http://schemas.datacontract.org/2004/07/PSRMWebService.Model.Version1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ID>0</ID><MailingAddress i:nil="true"/><Mask>Name</Mask><Name>Rykercom</Name><PhysicalAddress i:nil="true"/></Client>

你在最后看到的是我需要发送到服务器的序列化数据块(Model.Client 类型),这是使用

添加到请求中的
Request.AddParameter("application/xml; charset=utf-8", DataPacket, RestSharp.ParameterType.RequestBody);

其中 DataPacket 是使用 DataContractSerializer 创建的序列化 blob

现在如果我改变代码来调用

Client.ExecuteAsyncPost<Model.Client>(Request, (response, handle) => { OnFindClientAsyncComplete(response, handle, Callback ); }, "POST");

使用 Fiddler 我得到一个完全不同的数据包,没有正文,没有内容类型,因此服务器响应失败。

POST http://localhost.:49165/Services/Client/ClientAdminService/FindClient HTTP/1.1
Timestamp: Monday, March 18, 2013 2:35:08 AM
X-PS-Authentication: YADAYADA:<deleted for bevity>==
Accept: application/xml
User-Agent: RestSharp 104.1.0.0
Host: localhost.:49165
Content-Length: 0
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

X-PS-Authentication 只是一个自定义的身份验证字符串。有人知道为什么异步调用给我留下了一个空的消息正文吗?

【问题讨论】:

    标签: c# rest restsharp


    【解决方案1】:

    简单的答案是克隆当前的 github 存储库,然后自己构建它。看来 executeasync 的修复程序已经在树中了。

    拥有 Nuget 包的任何人都可以将其更新到最新的来源吗?

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-19
      • 2022-11-16
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多