Jan 09
HttpClient looks very nice, as it supports many HTTP actions. I tried the webpage download code, but encountered an encoding issues with Chinese web pages.
Language encoding is always a problem for non-English developers, especially Asian developers, whose languages are encoded in 2 bytes for each character.
After playing with the source code for hours, I finally googled a very simple solution. Here it comes:
-
-
HttpClient client = new HttpClient();
-
HttpMethod method = new GetMethod(url);
-
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "GBK");
-
// …. set other parameters
-
try {
-
int statusCode = client.executeMethod(method);
-
// other operations
-
}
-
catch{
-
// exception handling
-
}
-
Though spent hours, I am very glad that the solution is very simple.