connection timeout

Do you have any idea why my client implementation is failing and getting a timeout error, where as it works well from standard browser?

String urlString="www.myurl.com/test"

System.setProperty("java.protocol.handler.pkgs","javax.net.ssl");

java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

URL url = new URL(urlString);

// Open a HTTP connection to the URL

conn = (HttpsURLConnection) url.openConnection();

// Allow Inputs

conn.setDoInput(true);

// Allow Outputs

conn.setDoOutput(true);

// Don't use a cached copy.

conn.setUseCaches(false);

// Use a post method.

conn.setRequestMethod("POST");

conn.setRequestProperty("Connection", "Keep-Alive");

conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);

DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );

dos.writeBytes(twoHyphens + boundary + lineEnd);

dos.writeBytes("Content-Disposition: form-data; name=\"upload\";"

+ " filename=\"" + fileName +"\"" + lineEnd);

dos.writeBytes(lineEnd);

// create a buffer of maximum size

bytesAvailable = inputStream.available();

bufferSize = Math.min(bytesAvailable, maxBufferSize);

buffer = new byte[bufferSize];

// read file and write it into form...

bytesRead = inputStream.read(buffer, 0, bufferSize);

while (bytesRead > 0)

{

dos.write(buffer, 0, bufferSize);

bytesAvailable = inputStream.available();

bufferSize = Math.min(bytesAvailable, maxBufferSize);

bytesRead = inputStream.read(buffer, 0, bufferSize);

}

// send multipart form data necesssary after file data...

dos.writeBytes(lineEnd);

dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

// close streams

inputStream.close();

dos.flush();

dos.close();

I am getting error (java.net.ConnectException: Connection timed out: connect) in at the following line

DataOutputStream dos = new DataOutputStream( conn.getOutputStream() );

Where as when I am trying the same url using browser, it works just fine - any idea what I am screwing up?

[2246 byte] By [Amit.Khana] at [2007-10-3 5:14:45]
# 1
Probably you are behind a firewall and your browser has proxy settings but your Java code doesn't. See java.net.Proxy or https.proxtHost/proxyPort.BTW lines 2 and 3 aren't necessary from JDK 1.4 onwards.
ejpa at 2007-7-14 23:21:18 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2
yes, you are correct - i understand it. Is it possible to handle it from java? I mean how java could get through the proxy to post to the specified url - or it is not possible to do through java, when I am behind a firewall.
Amit.Khana at 2007-7-14 23:21:18 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3
I've already answered these questions.
ejpa at 2007-7-14 23:21:18 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...