2015-08-19 105 views
1

不知何故Fiddler不捕獲我從我提供的HttpClient發送的帖子。Fiddler不捕獲Apache HttpClient post

但是,當我在C#中使用HttpClient發送同一文章到同一臺服務器時,Fiddler會攔截會話。

我的Java代碼:

private DefaultHttpClient client = new DefaultHttpClient(); 
private HttpContext context = new BasicHttpContext(); 
private BasicCookieStore store = new BasicCookieStore(); 

public Client() throws URISyntaxException { 
    context.setAttribute(ClientContext.COOKIE_STORE, store); 
    logIn(); 
} 

private void logIn() throws URISyntaxException { 
    HttpUriRequest login = RequestBuilder.post() 
      .setUri(new URI("http://www.derpforum.nl")) 
      .addParameter("username", "Kattoor4") 
      .addParameter("password", "XXXX") 
      .addHeader("Referer", "http://www.derpforum.nl/") 
      .build(); 
    try (CloseableHttpResponse response = client.execute(login, context)) { 
     HttpEntity entity = response.getEntity(); 
     BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); 
     String line; 
     while ((line = reader.readLine()) != null) 
      System.out.println(line); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

有什麼想法?謝謝!

回答

0

您可能需要配置Java才能在代碼中使用Fiddler作爲代理,或者通過設置相關的Java系統屬性如下。 See this question.

-Dhttp.proxyHost=127.0.0.1 
-Dhttp.proxyPort=8888