本文介绍了使用 JsonServiceClient 获取 HttpResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 servicestack 的新 API 从其余服务方法之一返回 HttpResult.有没有办法使用 JsonServiceClient 获取 HttpResult?

I am returning HttpResult from one of the rest service methods using servicestack's new API. Is there a way to get the HttpResult using the JsonServiceClient?

例如:JSonServiceClient.Send("DELETE","person", new { PersonID = 30 });

我想检查 httpresult 中的标头信息.

I want to inspect the header information from the httpresult.

谢谢.

推荐答案

没有来自 ServiceStack Web 服务的 HttpResult 客户端响应这样的东西.

There's no such thing as a HttpResult client response from a ServiceStack web service.

您使用 HttpResult 来自定义从您的服务返回的 HTTP 响应,例如添加额外的 HTTP 标头.但是客户端看到的响应正文仍然只是响应 DTO(如果有).

You use a HttpResult to customize the HTTP Response that's returned from your service, e.g. Add additional HTTP Headers. But the response body the client sees is still only the Response DTO (if any).

使用 fiddler、wireshark、chome web 检查器(如果这是一个 Ajax 调用)或类似 ServiceStack 的 请求 Logger 插件 以检查 HTTP 流量.

Use fiddler, wireshark, chome web inspector (if this is an Ajax call) or something like ServiceStack's Request Logger plugin to inspect the HTTP traffic.

还要考虑使用适当的客户端 REST API,例如 client.Delete()client.Get() 等,而不是重载 T.Send() 方法(通常是 POST).

Also consider using the appropriate Clients REST API like client.Delete(), client.Get() etc instead of overloading the T.Send() method (which is usually a POST).

在 ServiceClient 中使用 Typed DTO 而不是不支持的匿名类型.

Use Typed DTOs in the ServiceClient instead of anonymous types which are not supported.

ServiceStack 的服务客户端提供 本地全局 WebResponse(和请求)过滤器,您可以使用这些过滤器来检查为该请求返回的 WebClient 的 HttpWebResponse,例如:

ServiceStack's Service Clients provide Local and Global WebResponse (and Request) filters that you can use to introspect the WebClient's HttpWebResponse returned for that request, e.g:

client.ResponseFilter = httpRes => {
   httpRes.Headers.. //do something with returned headers
};
client.Delete(new Person { Id = 30, ...});

这篇关于使用 JsonServiceClient 获取 HttpResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 09:30