2014-10-03 88 views
2

团队,提琴手没有捕获LINQPad上webClient的本地流量

我有以下LINQPad的简单WebClient调用。我怎么尝试Fiddler只是拒绝捕捉。 我只是没有办法。我尝试了localhost,localhost(带点),localhost.fiddler和我的机器名,而不是127.0.0.1。提琴手根本没有兴趣去捕捉这一切。任何人都有任何想法。

void Main() 
{ 
    CookieWebClient client = new CookieWebClient() 
    {  
     Proxy = new WebProxy("127.0.0.1", 8888) // Fiddler 
    };    
    Console.WriteLine(client.DownloadString(url)); // Cookie is created here 
    Console.WriteLine(client.DownloadString(url)); // In this request, the cookie gets sent back to the web API 
    Console.WriteLine("Done"); 
} 

// Define other methods and classes here 

public class CookieWebClient : WebClient 
{  
    private CookieContainer jar = new CookieContainer(); 
    protected override WebRequest GetWebRequest(Uri address)  
    {   
     WebRequest request = base.GetWebRequest(address);      
     HttpWebRequest webRequest = request as HttpWebRequest;   
     if (webRequest != null)    
      webRequest.CookieContainer = jar;      
     return request;  
    } 
} 
string url = "http://localhost:21531/api/employees/12345"; 

回答

7

你还没有解释到底发生了什么当您尝试。

.NET框架绕过任何HTTP/HTTPS请求localhost代理,所以你必须使用localhost.fiddlerstring url主机。当你这样做,有两种可能性:

  1. 请求成功,这意味着小提琴手捕获交通
  2. 请求失败,这意味着你的客户端没有正确配置来代理其请求。
+0

嗨埃里克,你的建议改变字符串的URL做窍门。以下终于奏效。 string url =“http://localhost.fiddler:21531/api/employees/12345”;一个多小时我只操作Proxy = new WebProxy(“127.0.0.1”,8888);我提到了不同的组合。非常感谢。 – VivekDev 2014-10-04 03:49:16

+0

我正在使用LinqPad与HttpClient。我有:'var webAddr =“http://localhost.fiddler:53733 /”;但Fiddler仍然没有看到任何东西。 – 2016-08-23 18:07:47

+0

@MKenyonII - 查看上面的答案。如果请求失败,则表示您的代理没有正确配置。 – EricLaw 2016-08-25 14:53:53