sockslib
sockslib copied to clipboard
How to visite https url with sockslib?
this method works fine when the url contains http, but it wouldn't works when the url contains https. for example: works fine: getResponse(new URL("http://www.worldjournal.com/")); don't work: getResponse(new URL("https://google.com/")); public static String getResponse(URL url){ String result = ""; StringBuilder builder = null; InputStream inputStream = null; OutputStream outputStream = null; Socket socket = null; int length = 0; byte[] buffer = new byte[1024]; try { SocksProxy proxy = new Socks5("x.x.x.x", 1080, new UsernamePasswordCredentials("x", "x")); socket = new SocksSocket(proxy, new InetSocketAddress(url.getHost(), url.getPort())); inputStream = socket.getInputStream(); outputStream = socket.getOutputStream(); PrintWriter printWriter = new PrintWriter(outputStream); printWriter.print("GET " + url + " HTTP/1.1\r\n"); printWriter.print("Host: " + url.getHost() + "\r\n"); printWriter.print("\r\n"); printWriter.flush();
builder = new StringBuilder("");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((length = inputStream.read(buffer)) > 0) {
System.out.print(new String(buffer, 0, length));
builder.append(new String(buffer, 0, length));
}
inputStream.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}
Sorry, SocksSocket
dose not support SSL because it's super class is java.net.Socket
.
javax.net.ssl.SSLSocket were the super class for SocksSocket, the https url would be supported in theory?
Yes.