Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to get Proxy working with Socket

I am trying to get Proxy working with Socket. But everytime I tried, it would returned a "Exception in thread "pool-1-thread-1" java.lang.IllegalArgumentException: Invalid Proxy" exception error

at java.net.Socket.(Socket.java:131)

But if its Proxy.Type.SOCKS, it works.

public void Test()
{
   Socket s = null;
   SocketAddress addr = null;
   Proxy proxy = null;

   addr = new InetSocketAddress("127.0.0.1", 8080);
   proxy = new Proxy(Proxy.Type.HTTP, addr);
   socket = new Socket(proxy); // This is the line that is triggering the exception
}
like image 529
user303907 Avatar asked Feb 04 '26 08:02

user303907


1 Answers

Sadly this is a bug in (Oracle) Java - only DIRECT and SOCKS proxy is supported for Socket. See https://bugs.java.com/bugdatabase/view_bug?bug_id=6370908.

like image 170
Martin Ždila Avatar answered Feb 05 '26 21:02

Martin Ždila



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!