2015-04-23 73 views
3

我一直有问题让小提琴拿起自我托管的asp.net web api的流量。我的情况可能有点不同,因为托管web api的同一个应用程序也在使用它(是的,我们有理由这么做:))。我们正在使用HttpClient。以下是我试过的东西:似乎无法得到代理HttpClient的提琴手

  1. 添加一个HttpClientHandler并设置代理。
  2. 增加了以下内容的app.config

    <system.net> 
    <defaultProxy> 
        <proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://localhost:8888"/> 
    </defaultProxy> 
    

  3. 试图打从单独的.NET客户端的客户端的API(想着同一进程占用托管它是不允许API因为它全部是内部进程,所以要捕获的流量)。

现在,如果我打开一个网页浏览器或邮递员本地和打API则流量将被正确捕获

下面是客户端代码:

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并捕获流量(即使在生产中),而无需更改源代码。

回答

4

不幸的是,.NET Framework是硬编码绕过本地主机地址的代理服务器(在这里看到我的功能要求:https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6359204-support-the-loopback-token-in-proxy-bypass-lists

要解决这一点,改变从http://localhost:8085您的请求网址http://localhost.fiddler:8085和提琴手将搭载请求。

+0

谢谢,工作!为我节省了很多时间旋转我的轮子。我也提供了您创建的用户发言条目。 – coding4fun