<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Comments for Using URLConnection with a Proxy Server by Daniel Horn</title>
<link rel="alternate" type="text/plain" href="http://dn.codegear.com/article/29783" title="Using URLConnection with a Proxy Server by Daniel Horn" />
<link rel="self" type="application/atom+xml" href="http://dn.codegear.com/article/29783/feed" title="Comments for Using URLConnection with a Proxy Server by Daniel Horn" />
<id>http://dn.codegear.com/article/29783</id>
<updated>2008-10-07T02:09:31-07:00</updated>
<entry>
<title>Using URLConnection with a Proxy Server by Daniel Horn</title>
<author>
<name>Craven Weasel</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=40589</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=40589</id>
<updated>2007-10-22T03:55:10-07:00</updated>
<published>2007-10-22T03:55:10-07:00</published>
<summary>Using URLConnection with a Proxy Server by Daniel Horn</summary>
<content>Much simpler to use this before your connection System.setProperty(&quot;http.proxyHost&quot;,&quot;PROXY_SERVER_IP_OR_NAME&quot;);System.setProperty(&quot;http.proxyPort&quot;,&quot;PORT NUMBER PROXYservice&quot;);http://forum.java.sun.com/thread.jspa?threadID=729144&amp;messageID=4197363</content>
</entry>
<entry>
<title>Using URLConnection with a Proxy Server by Daniel Horn</title>
<author>
<name>ajay a</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=39521</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=39521</id>
<updated>2006-10-12T09:04:23-07:00</updated>
<published>2006-10-12T09:04:23-07:00</published>
<summary>Using URLConnection with a Proxy Server by Daniel Horn</summary>
<content>Hello Daniel,I was able to implement this on my application but I am unable to do for the HTTPS protocol (URLConnection with ProxyServer for HttpsConneciton) I am getting Connection refused error I have implemented like this url = new URL(url.getProtocol(), // HTTPS              proxyHost, //MY PROXY SERVER HOST              proxyPort, //PROXY PORT ( I tried with 443 also)              url        //Complete Https URL              );Please advise me if you would know how to achieve dynamic Https connection, I tried with HttpsProxyHost but it's not feasible on Multithreaded Environment on single JVM Thanks Ajay</content>
</entry>
<entry>
<title>Using URLConnection with a Proxy Server by Daniel Horn</title>
<author>
<name>Craven Weasel</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=38935</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=38935</id>
<updated>2006-02-21T07:56:10-08:00</updated>
<published>2006-02-21T07:56:10-08:00</published>
<summary>Using URLConnection with a Proxy Server by Daniel Horn</summary>
<content>The sample doesnt work and request doesn't go beyond proxy.</content>
</entry>
<entry>
<title>Using URLConnection with a Proxy Server by Daniel Horn</title>
<author>
<name>Joseph Wang</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=34935</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=34935</id>
<updated>2003-07-10T11:34:51-07:00</updated>
<published>2003-07-10T11:34:51-07:00</published>
<summary>Using URLConnection with a Proxy Server by Daniel Horn</summary>
<content>I read this article and coied the code to my program.But it can't work when I run it .I traced it ,fund  it can't to get connection  at :HttpURLConnection h = (HttpURLConnection) c;h.connect();When I run the original code in JBuilder, it works.I don't have proxy, so I put null in the &quot;strProxy&quot;</content>
</entry>
<entry>
<title>Using a HTTPS URLConnection with a Proxy Server</title>
<author>
<name>Richard Durley</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=34812</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=34812</id>
<updated>2003-06-19T02:09:10-07:00</updated>
<published>2003-06-19T02:09:10-07:00</published>
<summary>Using a HTTPS URLConnection with a Proxy Server</summary>
<content>After much reading and a day of messing around I finally stumbled on a configuration that workswhen wanting to connect to a https site via a proxy server I hope it is of use.import com.sun.net.ssl.*;import Base64Converter;import java.net.*;import java.io.*;import java.util.*;  /**   * The following code demonstrates how you can connect using HTTPS through a proxy server    * @author richard.durley@eds.com   */  public static void testHttpsTunnelledThroughProxy()  {    HttpsURLConnection con = null;    BufferedReader reader = null;    InputStream in = null;    String inLine = null;    try    {      //does not seem to matter if you set this or not !      System.getProperties().put( &quot;proxySet&quot;, &quot;true&quot; );      //Define the https proxy server and port if your using https connections      System.getProperties().put( &quot;https.proxyHost&quot;, &quot;xxx.xxx.xxx.xxx&quot; );      System.getProperties().put( &quot;https.proxyPort&quot;, &quot;443&quot; );       //The properties to define the proxy user and password dont seem to work      //you will need to add the Proxy-Authorization header manually to the request      //see futher down      System.getProperties().put(&quot;https.proxyUser&quot;, &quot;userid&quot;);      System.getProperties().put(&quot;https.proxyPassword&quot;, &quot;password&quot;);*/      //Add the route to your cacerts filestore (or a filestore of your choice)      //you'll find ca certs at java_home$/jre/lib/security      //Seems that if you dont add this java will not always find the certificate required for to trust      //the SSL connection.      //      //Note if you still get a CertificateException &quot;could not find trusted      //certificate&quot; then you will need to import the public certificate of the website you are connecting      //to into the keystore using keytool -import -keystore cacerts -file thecert.cer -alias thecertname      //you'll be promoted to enter a password it is 'changeit'  by default.      System.setProperty(&quot;javax.net.ssl.trustStore&quot;, &quot;d:/j2sdk1.4.1_02/jre/lib/security/cacerts&quot;);      //Defines the internal ssl protocol implementation      System.setProperty(&quot;java.protocol.handler.pkgs&quot;,&quot;com.sun.net.ssl.internal.www.protocol&quot;);      //Adds the ssl provider      java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());      //Define the url you want to connect to, note the name of the host in the certificate needs to match the host in the URL      URL url = new URL(&quot;https://www.mysecurehost.com/mysecurepage.html&quot;);      System.out.println(url.toExternalForm());      //Open the https URL connection      con = (HttpsURLConnection) url.openConnection();      //Follow redirects if necessary      con.setFollowRedirects(true);      //Set the Proxy-Authorization header for basic proxy authorization      //If you dont do this you will get       //'Unable to tunnel through proxy. Proxy returns &quot;HTTP/1.0 407 Authenticate required' IOException      //You also will need a base64 encoder to encode the userid and password string      con.setRequestProperty( &quot;Proxy-Authorization&quot;, &quot;Basic &quot; + Base64Converter.encode(&quot;proxyuserid:proxypassword&quot;));      //get the input stream      in = con.getInputStream();      reader = new BufferedReader(new InputStreamReader(in));      inLine = reader.readLine();      //read all lines      while (inLine != null)      {        System.out.println(inLine);        inLine = reader.readLine();      }      //read the cookie string if you want to store it (especially useful to capture the      //session id if returned from the server you can then add this to future requests      String cookie = con.getHeaderField(&quot;Set-Cookie&quot;);      int index = cookie.indexOf(&quot;;&quot;);      if(index &gt;= 0) cookie = cookie.substring(0, index);         Balance.cookie=cookie;      //close      reader.close();      in.close();      con.disconnect();    }    catch (Exception e)    {      e.printStackTrace(System.out);    }  }</content>
</entry>
<entry>
<title>Using URLConnection with a Proxy Server by Daniel Horn</title>
<author>
<name>Craven Weasel</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=34771</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=34771</id>
<updated>2003-06-10T14:51:45-07:00</updated>
<published>2003-06-10T14:51:45-07:00</published>
<summary>Using URLConnection with a Proxy Server by Daniel Horn</summary>
<content>Hi,I've followed exctly the way you described in the article.I specified the IP and port # of proxy. For some reason,I've been getting an exception at run time. It's something likethisjava.net.ConnectException: Connection timed out: connectThread 0 connect to serverMy first guess is that I put an invalid proxy's IP address.I already tried to browse through the proxy by using Internet Explorer and it works fine. Any possible solution. Any help is very appreciatedThank you very much</content>
</entry>
<entry>
<title>Using URLConnection with a Proxy Server by Daniel Horn</title>
<author>
<name>Rainer Warth</name>
<uri>http://threads.codegear.com/threads/threads.exe/userall?commentid=34534</uri>
</author>
<id>http://threads.codegear.com/threads/threads.exe/view?commentid=34534</id>
<updated>2003-04-28T06:28:29-07:00</updated>
<published>2003-04-28T06:28:29-07:00</published>
<summary>Using URLConnection with a Proxy Server by Daniel Horn</summary>
<content>Dear Daniel,   I enjoyed reading your article. I helped me very much during my current project. I agree with you that some documentation or example was missing until now.Thanks, Rainer</content>
</entry>
</feed>
