Open fancellu opened 4 years ago
BTW, this is an example of it working just fine with HttpURLConnection
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.URL;
import java.net.*;
public class TorNoDNSIssue {
public static String readInputStreamAsString(InputStream in)
throws IOException {
BufferedInputStream bis = new BufferedInputStream(in);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
byte b = (byte)result;
buf.write(b);
result = bis.read();
}
return buf.toString();
}
public static void main(String[] args) throws Exception {
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("localhost", 9150));
URL url = new URL("http://check.expyuzz4wqqyqhjn.onion");
InputStream is=url.openConnection(proxy).getInputStream();
String string = readInputStreamAsString(is);
is.close();
System.out.println(string);
}
}
@fancellu Your HttpURLConnection based sample doesn't work for me. And as far as I know, Java doesn't support this, see https://bugs.openjdk.java.net/browse/JDK-8028776.
Mmm, actually, I see the DNS resolution in Charles, not in AHC, so I guess it works now and the Java issue should be closed.
Charles?
It very much does work for me:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Welcome to hetzner-hel1-03!</TITLE>
</HEAD>
<BODY>
<H1>Welcome to hetzner-hel1-03!</H1>
This is hetzner-hel1-03, a system run by and for the <a href="http://www.torproject.org/">Tor Project</a>.
She does stuff.
What kind of stuff and who our kind sponsors are you might learn on
<a href="http://db.torproject.org/machines.cgi?host=hetzner-hel1-03">db.torproject.org</a>.
<P>
<HR NOSHADE />
<FONT size="-1">torproject-admin</FONT>
</BODY>
</HTML>
Process finished with exit code 0
BTW, I love Gatling,
I got this working for Gatling (DNS resolution was already working fine for HTTP proxies), see https://github.com/gatling/gatling/issues/3835.
Now, regarding AHC, honestly, the code base is very different now and I don't now if/when I'll have time for this someday.
The best solution would be to contribute a fix.
My work around is to use okhttp
https://gist.github.com/fancellu/df6dde59249edf8401b28bbc44a78cbc
@TomGranot I'm also noticing this for other Socks 5 proxy traffic
Run up a socks proxy, for example Tor browser proxy on port 9150
Run this code
I get
If I point it at
https://check.torproject.org/
it works fineDo I have to do something else to make it not fail?
Thanks