4

以前,我在httpclient3從HttpClient的轉換3至HttpClient的4(Cookie政策)

// To prevent cookie warnings. 
httpClient.getParams().setParameter("http.protocol.single-cookie-header", true); 
httpClient.getParams().setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY); 

下面的代碼我想知道,什麼是httpclient4等價代碼,因爲我在第二收到錯誤線。

// To prevent cookie warnings. 
httpClient.getParams().setParameter("http.protocol.single-cookie-header", true); 
// ??? compilation error in this line. 
// org.apache.commons.httpclient cannot be resolved to a variable 
httpClient.getParams().setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY); 
+1

什麼是錯誤? – kosa

+0

更新了錯誤信息。 –

+1

看來你有案件問題的問題。 httpclient應該是httpClient。 – kosa

回答

0

由於4.3版getParams()ClientPNamesCookiePolicy都已過時。爲了達到同樣的效果,你必須這樣做:

final RequestConfig params = RequestConfig 
     .custom() 
     .setCookieSpec(CookieSpecs.IGNORE_COOKIES) 
     .build(); 

httpPost.setConfig(params);