How to get URL connection using proxy in java?

前端 未结 2 1861
忘掉有多难
忘掉有多难 2020-12-11 01:33

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.10         


        
2条回答
  •  长情又很酷
    2020-12-11 02:06

    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");
    

提交回复
热议问题