I am trying to create URL connection using a proxy at run time. My code is below:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.0.2.100", 80));
HttpURLConnection connection =
(HttpURLConnection)new URL("http://abc.example.com").openConnection(proxy);
But this is not working. Anybody know why?
Proxy URL (-PROXY)Use the Proxy URL adapter command ( -PROXY ) to specify the URL to connect to a proxy server. You must specify a file name for the file to be transferred. Specify the user name to connect to the proxy server. Unless you are also specifying a password, this must be followed by @ if you specify host .
Type. HTTP, new InetSocketAddress("10.0. 0.1", 8080)); conn = new URL(urlString). openConnection(proxy);
adding answer for the help of future visitors
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.0.2.100", 80));
HttpURLConnection connection =(HttpURLConnection)new URL("http://abc.example.com").openConnection(proxy);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestProperty("Accept", "text/xml, application/xml");
connection.setRequestMethod("POST");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With