B4J Question httpjob with SOCKS5 proxy?

wimpie3

Well-Known Member
Licensed User
Longtime User
Hi there,

I'm currently using httpjob to do a poststring to a server.

However, one of my clients has to use a SOCKS5 proxy server for all his network traffic.

I'd like httpjob to tell the server name, userid and password to use for the proxy connection, but "out of the box" okhttp in B4J doesn't seem to support this?

I've found some solutions on the forum for http(s) proxies, but not for SOCK5 proxies. Any help here please?
 

MarcoRome

Expert
Licensed User
Longtime User
Do you read this too ?


 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Yes. The code in the first post seems to be for http proxies. I'm dealing with a socks proxy here.

Edit: also found this online, not sure if that's the reason why it's not working:
B4X:
JDK HttpClient doesn't support socks proxies, only HTTP(S) proxies, even though types like java.net.Proxy.Type.SOCKS do exist. This problem isn't documented at all in the Java JDK, which causes Java to silently disregard the socks proxy when you try to use it, by using a non-proxy connection.

This problem is reported as a bug in 2018 to OpenJDK, but hasn't been fixed yet: https://bugs.openjdk.java.net/browse/JDK-8214516
 
Last edited:
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Apparently the way to go is this:

B4X:
    SetSystemProperty("socksProxyHost", "nameoftheserver")
    SetSystemProperty("socksProxyPort", 1080)
    SetSystemProperty("socksProxyVersion",5)
    SetSystemProperty("java.net.socks.username", "username")
    SetSystemProperty("java.net.socks.password", "password")

But I get a java.net.SocketException: SOCKS : authentication failed. If I'm correct you need to write an authenticator routine in Java? Who can help me with this? Should only be a couple of lines I guess...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…