SocketException: Connection reset , using HttpURLConnection

hello everybody, i'm using this to read a xml from internet:

URL url;

HttpURLConnection urlcon;

url =new URL (urlString);

System.out.print("Connecting ....\t");

urlcon = (HttpURLConnection)url.openConnection();

if(!urlcon.getResponseMessage().equals("OK"))

return -1;

System.out.println("Done!");

it gives me:

java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(Unknown Source)

at java.io.BufferedInputStream.fill(Unknown Source)

at java.io.BufferedInputStream.read1(Unknown Source)

at java.io.BufferedInputStream.read(Unknown Source)

at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)

at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)

at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unkno

at java.net.HttpURLConnection.getResponseCode(Unknown Source)

at java.net.HttpURLConnection.getResponseMessage(Unknown Source)

when i do urlcon.getResponseMessage()....

Any ideas why this happens?

PS: when i try the same URL in a browser, it opens the file fine .....

[1394 byte] By [Mackleina] at [2007-11-27 0:28:39]
# 1
Please show your URL.
Michael.Nazarov@sun.coma at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 2
i'm sorry, forgive me, but i can't post the url here...........
Mackleina at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 3
As you wish :)
Michael.Nazarov@sun.coma at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 4
the thing is that other url's work fine, but this one does not, even when a browser can load it fine....
Mackleina at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 5
Continue your researches and success will come to you.
Michael.Nazarov@sun.coma at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 6
It could be that the browser uses a proxy, and your code does not. I am guessing you are in a work environment that may well have a proxy server and would explain this.....or i didn't read that other URL's worked...
robtafta at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 7

> It could be that the browser uses a proxy, and your

> code does not. I am guessing you are in a work

> environment that may well have a proxy server and

> would explain this.

There is no proxy, i connect directly to internet..

> or i didn't read that other URL's worked...

Others url's have worked fine....

Mackleina at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 8
Then probably the server that you are connecting to doesn't like the way you are connecting to it.
DrClapa at 2007-7-11 22:30:07 > top of Java-index,Java Essentials,Java Programming...
# 9

My suggestion is run that with Wireshark (ethereal) monitoring the data. That way you can see what is really going on in the traffic and compare that to the browsers traffic. It's possible that the server is attempting to block bots, and I think Java tells the server that it is a JRE connecting and not a normal browser. There are ways to get around that though if that is the issue.

robtafta at 2007-7-11 22:30:08 > top of Java-index,Java Essentials,Java Programming...
# 10

> My suggestion is run that with Wireshark (ethereal)

> monitoring the data. That way you can see what is

> really going on in the traffic and compare that to

> the browsers traffic. It's possible that the server

> is attempting to block bots, and I think Java tells

> the server that it is a JRE connecting and not a

> normal browser. There are ways to get around that

> though if that is the issue.

You were right, the first thing i tried was to set the user-agent property in the request, and that was it, looks like the server was blocking me, thx everybody

Mackleina at 2007-7-11 22:30:08 > top of Java-index,Java Essentials,Java Programming...