如何修复java.io.IOException:无法通过代理进行隧道。“代理申报表”;HTTP/1.1 400错误请求“;?
调用HttpURLConnection.getOutputStream()时,我得到以下IOException: 无法通过代理进行隧道传输。代理返回“HTTP/1.1 400错误请求” 代码片段:如何修复java.io.IOException:无法通过代理进行隧道。“代理申报表”;HTTP/1.1 400错误请求“;?,java,proxy,httpurlconnection,ioexception,bad-request,Java,Proxy,Httpurlconnection,Ioexception,Bad Request,调用HttpURLConnection.getOutputStream()时,我得到以下IOException: 无法通过代理进行隧道传输。代理返回“HTTP/1.1 400错误请求” 代码片段: public static void main(String[] args) throws MalformedURLException, IOException { HttpURLConnection conn = (HttpURLConnection) new URL("https:
public static void main(String[] args) throws MalformedURLException, IOException {
HttpURLConnection conn = (HttpURLConnection) new URL("https://example.com")
.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("88.198.50.103", 3128)));
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os)) {
osw.write("Hello");
osw.flush();
} catch (IOException e) {
System.err.println("Caught exception while opening outputstream.");
e.printStackTrace();
}
System.out.println("Response: " + conn.getResponseMessage());
}
Caught exception while opening outputstream.
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at application.Main.main(Main.java:31)
Response: Bad Request
生产输出:
public static void main(String[] args) throws MalformedURLException, IOException {
HttpURLConnection conn = (HttpURLConnection) new URL("https://example.com")
.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("88.198.50.103", 3128)));
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os)) {
osw.write("Hello");
osw.flush();
} catch (IOException e) {
System.err.println("Caught exception while opening outputstream.");
e.printStackTrace();
}
System.out.println("Response: " + conn.getResponseMessage());
}
Caught exception while opening outputstream.
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
at application.Main.main(Main.java:31)
Response: Bad Request
我尝试了在互联网上找到的随机免费代理,所有代理都有相同的输出
这和我的电脑有关吗?或者我使用代理的代码是错误的
SocketAddress addr = new InetSocketAddress("104.248.63.17",30588);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
URL url = new URL("https://www.proxy-listen.de/Proxy/Proxyliste.html");
URLConnection conn = url.openConnection(proxy);
//follow code reads html from url
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
这个代码对我有用。我搜索了一个socks5代理,然后它可以与类型socks一起工作
这个代码对我有用。我搜索了一个socks5代理,然后它可以与类型socks一起工作