这段代码给了我内容,但是一些俄罗斯字符隐藏了我的广场...谁知道如何设置utf-8或cp1251 charset代理获取内容。使用代码跳舞不会对我产生任何影响。 getBytes等方法无法给我正常的结果。
URL url = new URL(linkCar);
String your_proxy_host = new String(proxys.getValueAt(xProxy, 1).toString());
int your_proxy_port = Integer.parseInt(proxys.getValueAt(xProxy, 2).toString());
Proxy proxy = null;
System.out.println(proxys.getValueAt(xProxy, 3).toString());
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(your_proxy_host, your_proxy_port));
HttpURLConnection connection = (HttpURLConnection)url.openConnection(proxy);
connection.setConnectTimeout(16000);
connection.connect();
proxys - 表模型,其中代理列表; 并且可能是谁知道如何设置connect throw socks-proxy
答案 0 :(得分:1)
对于UTF-8,尝试更改行
BufferedReader buffer_input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
到
BufferedReader buffer_input = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
如果要更改charset,可以将charset名称更改为另一个名称。