简体   繁体   English

ServiceStack新API-如何获取原始请求/响应

[英]ServiceStack New API - How to get raw request/response

I'm using the new ServiceStack.Client to consume a ServiceStack API, and to make a simple prototype to a client, as they are using PHP, I would like to show the raw request and response that internally ServiceStack is using to make the request. 我正在使用新的ServiceStack.Client来使用ServiceStack API,并为客户端制作一个简单的原型,因为他们使用的是PHP,我想展示ServiceStack内部用于发出请求的原始请求和响应。

Is there anything I can hook up in the client side to get the raw URL and data that is been sent to the API as well the raw json that we're getting from the API call? 我是否可以在客户端连接任何东西,以获取发送到API的原始URL和数据以及从API调用获取的原始json?

I'm simply using, as an example: 我只是使用一个例子:

var service = new JsonServiceClient(gko_url);
var response = service.Post<Authenticate>("/auth", new Authenticate()
{
    UserName = username,
    Password = password,
    RememberMe = true
});

If you are trying to inspect the raw HTTP request & response between the ServiceStack Client and service, the easiest way is to run the Fiddler proxy on the same PC as the client. 如果要检查ServiceStack客户端和服务之间的原始HTTP请求和响应,最简单的方法是在与客户端相同的PC上运行Fiddler代理。

Then set the ServiceStack client to use fidder as a proxy (running on localhost port 8888 by default): 然后将ServiceStack客户端设置为使用fidder作为代理(默认情况下在localhost端口8888上运行):

var client = new JsonServiceClient(gko_url);
IWebProxy webProxy = new WebProxy("http://localhost:8888");
client.Proxy = webProxy;
var response = client.Post<Authenticate>("/auth", new Authenticate()
{
    UserName = username,
    Password = password,
    RememberMe = true
});

You can then inspect the raw HTTP Request and Response between the client and the server via the Fiddler UI. 然后,您可以通过Fiddler UI检查客户端和服务器之间的原始HTTP请求和响应。 That will give you and others confidence the "over the wire" communication is pure HTTP+JSON , and language-independent. 这将使您和其他人充满信心,“在线”通信是纯HTTP + JSON的,并且与语言无关。

This may be more effective to "show off", since you are not asking the ServiceStack client to give you the raw HTTP communication - it is coming from a completely different application (Fiddler web proxy). “炫耀”这可能更有效,因为您不是在要求ServiceStack客户端提供原始的HTTP通信-它来自完全不同的应用程序(Fiddler Web代理)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM