tags:

views:

65

answers:

1

Hi,

I`m using the class HttpURLConnection this way:

HttpURLConnection con=(HttpURLConnection) servlet.openConnection();
int conResponseCode = con.getResponseCode();

Sometimes I`m getting conResponseCode as 0.

I tried to look in the net, and couldnt find what it means?

any idea why it occours? and what it states for?

Thanks, ray.

A: 

It's not a valid HTTP response, so it doesn't mean anything per se.

Looking at the source of java.net.HttpURLConnection (which is what I presume you mean), it seems to just parse the integer status code out of the response line. Which would seem to imply that the remote server is returning a response along the lines of:

HTTP/1.0 0 XXX

(where XXX is some reason).

If you make the request yourself with telnet (or similar program), or can put breakpoints on Java sources in your debugger, you'll be able to see what is being sent back from the remote server in this case.

Either way, this is either a bug in the Java libraries (possible, but unlikely) or a weird response from the remote server. Getting the raw contents of the response will allow you to distinguish between the two, and then ping the relevant party with a bug report.

Andrzej Doyle
I cant catch the problem in debugger, coz it happens randomly. any idea how else I could catch the prob?thanks
rayman
A conditional breakpoint in the debugger would let you trigger this only when the return was going to be zero. If you're having problems reproducing it *at all*, that's a different matter entirely.
Andrzej Doyle
So there is no way I could see the details of the error through my code?
rayman
Hmmm... I think you could call `con.getHeaderField(0)` which should give you the status line being parsed. This may or may not be of any use, but you're right that you could send this to e.g. a log file when the zero code is returned, so you can see what's actually being parsed by the Java class.
Andrzej Doyle