我一直在尝试让Fiddler捕获自托管ASP.NET Web API的流量,但遇到了问题。我的情况可能有点不同,因为托管Web API的应用程序也在使用它(是的,我们有理由这样做 :))。我们正在使用HttpClient。这里是我尝试过的事情:
- Adding an HttpClientHandler and setting up the proxy.
added the following to app.config
<system.net> <defaultProxy> <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost:8888"/> </defaultProxy>
Tried to hit the api from a separate .net client client (thinking the same process consuming the api that is hosting it was not allowing the traffic to be captured since it was all Intra-process).
以下是客户端代码:
var handler = new HttpClientHandler();
handler.UseProxy = true;
handler.Proxy = new WebProxy("http://127.0.0.1",8888);
var client = new HttpClient(handler) {BaseAddress = new Uri(new Uri("http://localhost:8085"), "api/companies")};
HttpResponseMessage response;
using (client)
{
response = client.GetAsync(client.BaseAddress).Result;
}
var result = response.Content.ReadAsAsync<IEnumerable<Company>>().Result;
理想情况下,我希望能够在运行应用程序时仅打开 Fiddler 并捕获流量(即使在生产环境中),而无需更改源代码。