Java Http Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About java http status codes Us Learn more about Stack Overflow the company Business Learn more about hiring java response status code developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the
Android Http Status Code Constants
Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Read error response body in
Http Status Code Java Example
Java up vote 34 down vote favorite 7 In Java, this code throws an exception when the HTTP result is 404 range: URL url = new URL("http://stackoverflow.com/asdf404notfound"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.getInputStream(); // throws! In my case, I happen to know that the content is 404, but I'd still like to read the body of the response anyway. (In my actual case the response code java get http response code is 403, but the body of the response explains the reason for rejection, and I'd like to display that to the user.) How can I access the response body? java http httpurlconnection share|improve this question edited Jan 29 '14 at 16:34 Jonik 37.6k42179242 asked Mar 5 '09 at 1:46 Dan Fabulich 10.8k2479112 Are you sure the server is sending a body? –Hank Gay Mar 5 '09 at 1:50 What's the exception? –jdigital Mar 5 '09 at 2:05 @jdigital: the exception thrown by HttpURLConnection.getInputStream() is java.io.FileNotFoundException. (Mainly mentioning this for better googlability.) –Jonik Jan 29 '14 at 16:34 add a comment| 6 Answers 6 active oldest votes up vote 73 down vote accepted Here is the bug report (close, will not fix, not a bug). Their advice there is to code like this: HttpURLConnection httpConn = (HttpURLConnection)_urlConnection; InputStream _is; if (httpConn.getResponseCode() == 200) { _is = httpConn.getInputStream(); } else { /* error from server */ _is = httpConn.getErrorStream(); } share|improve this answer edited Oct 20 '14 at 18:16 answered Mar 5 '09 at 3:26 TofuBeer 42.4k987135 3 Wouldn't you want to get the error stream when the response code i
Method javax.xml.ws.http Class HTTPException java.lang.Object org.apache.commons.httpclient.httpstatus maven java.lang.Throwable java.lang.Exception java.lang.RuntimeException javax.xml.ws.WebServiceException javax.xml.ws.ProtocolException javax.xml.ws.http.HTTPException All Implemented Interfaces: Serializable public http://stackoverflow.com/questions/613307/read-error-response-body-in-java class HTTPException extends ProtocolException The HTTPException exception represents a XML/HTTP fault. Since there is no standard format for faults or exceptions in XML/HTTP messaging, https://docs.oracle.com/javase/7/docs/api/javax/xml/ws/http/HTTPException.html only the HTTP status code is captured. Since: JAX-WS 2.0 See Also:Serialized Form Constructor Summary Constructors Constructor and Description HTTPException(intstatusCode) Constructor for the HTTPException Method Summary Methods Modifier and Type Method and Description int getStatusCode() Gets the HTTP status code. Methods inherited from classjava.lang.Throwable addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, https://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpStatus.html status codes. All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and RFC2518 (WebDAV) are supported. Version: http://www.javacoffeebreak.com/faq/faq0079.html $Id: HttpStatus.java 608014 2008-01-02 05:48:53Z rolandw $ Author: Unascribed, Mike Bowler, Jeff Dever TODO: Internationalization of status code reason phrases See Also:StatusLine Field Summary staticint SC_ACCEPTED 202 Accepted (HTTP/1.0 - RFC 1945) staticint SC_BAD_GATEWAY 502 Bad Gateway (HTTP/1.0 - RFC 1945) staticint SC_BAD_REQUEST 400 Bad Request (HTTP/1.1 - RFC http status code 2616) staticint SC_CONFLICT 409 Conflict (HTTP/1.1 - RFC 2616) staticint SC_CONTINUE 100 Continue (HTTP/1.1 - RFC 2616) staticint SC_CREATED 201 Created (HTTP/1.0 - RFC 1945) staticint SC_EXPECTATION_FAILED 417 Expectation Failed (HTTP/1.1 - RFC 2616) staticint SC_FAILED_DEPENDENCY 424 Failed Dependency (WebDAV - RFC 2518) staticint SC_FORBIDDEN 403 Forbidden (HTTP/1.0 - RFC 1945) staticint SC_GATEWAY_TIMEOUT 504 Gateway Timeout (HTTP/1.1 - RFC 2616) staticint SC_GONE 410 Gone (HTTP/1.1 - RFC 2616) staticint SC_HTTP_VERSION_NOT_SUPPORTED 505 HTTP Version Not Supported (HTTP/1.1 - RFC 2616) staticint SC_INSUFFICIENT_SPACE_ON_RESOURCE Static constant for a 419 error. staticint