Home arrow static arrow Java Programming [Archive] - Can you Ignore Error Response Code in HttpUrlConnection?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Can you Ignore Error Response Code in HttpUrlConnection?
This topic has 4 replies on 1 page.

Posts:4
Registered: 7/30/04
Can you Ignore Error Response Code in HttpUrlConnection?  
Jul 30, 2004 1:42 PM



 
I have a problem with a HttpUrlConnection object throwing an IOException when it gets an HTTP Error Response code. Especially when there is an actual response from the server sent back that has more details in it that are actually helpful.

I would like to just tell the HttpUrlConnection ot ignore HTTP error responses and just pass along the page or data that was returned instead. I need to handle this myself.

The reason if it matters, is I am sending SOAP Envelopes, and if the Web Service doesn't like it, it will send an HTTP 500 Response Code, but it also sends a response SOAP Envelope that tells me exactly what is wrong.

Right now to get this response I have to use a Sniffer, or worse since it is HTTPS (ssl) i have to use the jvm's SSL debug mode, and pull the response out of the hex code.

I couldn't find anything about this, so I am afraid I am SOL, just hoping that there might be an obscure "feature" or "property" that can deal with this, that I can't find.

** 10 Duke Dollars to first person to provide a solution that works **
 

Posts:4
Registered: 7/30/04
Re: Can you Ignore Error Response Code in HttpUrlConnection?  
Jul 30, 2004 1:58 PM (reply 1 of 4)



 
Update:

Forgot to mention, because it throws an exception any time to try to get any content from the response, it makes it impossible to obtain it via the connection.
 

Posts:15
Registered: 12/20/99
Re: Can you Ignore Error Response Code in HttpUrlConnection?  
Jul 31, 2004 9:50 AM (reply 2 of 4)



 
You can try and use the getHeaderField(int) method
instead of getResponseCode or getResponseMessage.
This is just a guess since your problem description is a little vague.
 

Posts:951
Registered: 6/7/01
Re: Can you Ignore Error Response Code in HttpUrlConnection?  
Jul 31, 2004 2:26 PM (reply 3 of 4)



 
Just call the getErrorStream() method to read the error response. Eg.
HttpURLConnection conn = null;try {  conn = (HttpURLConnection)     new URL("http://www.google.com/givemea404").openConnection();} catch (Exception e) {  InputStream in = conn.getErrorStream();  int i = in.read();  while (i != -1) {    System.out.print((char) i);    i = in.read();  }}
 

Posts:4
Registered: 7/30/04
Re: Can you Ignore Error Response Code in HttpUrlConnection?  
Aug 2, 2004 11:24 AM (reply 4 of 4)



 
serlank ,

You rock, that is exactly what I was looking for. 10 points to you man!
 
This topic has 4 replies on 1 page.