Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to visite https url with sockslib? #8

Open
Sean66 opened this issue Sep 24, 2017 · 3 comments
Open

How to visite https url with sockslib? #8

Sean66 opened this issue Sep 24, 2017 · 3 comments

Comments

@Sean66
Copy link

Sean66 commented Sep 24, 2017

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();
}
@fengyouchao
Copy link
Owner

Sorry, SocksSocket dose not support SSL because it's super class is java.net.Socket.

@Sean66
Copy link
Author

Sean66 commented Sep 25, 2017

javax.net.ssl.SSLSocket were the super class for SocksSocket, the https url would be supported in theory?

@fengyouchao
Copy link
Owner

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants