我试图加载几个具有不同语言内容的网站。我只将俄罗斯内容视为<?>
元素。请帮助我将其解码为正确的符号。我的代码示例:
RequestTask t = new RequestTask();
response = t.doIt("http://google.ru"); //troubles
//response = t.doIt("http://stackoverflow.com"); //ok
//response = t.doIt("http://web.de/"); //ok
//response = t.doIt("http://www.china.com/"); // omg, it's ok too!
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
String response_string = new String(out.toByteArray(), "UTF-8");
请求代码:
public class RequestTask {
public HttpResponse doIt(String... uri)
throws ConnectTimeoutException, UnknownHostException, IOException{
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 6000);
HttpConnectionParams.setSoTimeout(params, 6000);
HttpClient httpclient = new DefaultHttpClient(params);
HttpResponse response = null;
Log.d(this.toString(), "HTTP GET to " + uri[0]);
response = httpclient.execute(new HttpGet(uri[0]));
Log.d(this.toString(), "response: " + response.getStatusLine().getReasonPhrase());
return response;
}
}