2014-10-03 65 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