Server Errors below:
If an error occurred, a HTTP status code 503 (Service Unavailable)
will be returned. The MIME type will be set in accordance with the
format parameter that was specified in the request. The body of the
the returned page will contain the string “Error:” followed by a
string with further details. If XHTML was requested, this message will
appear somewhere in the document inside aelement. If plain
text was requested, it will appear on the first line in the document.
So, I send request with wrong parameters -> server returns error 503 and page with text that describe where problem.
I use the java code below:
static BufferedReader getReader(String urlString) throws IOException {
HttpURLConnection connection;
BufferedReader reader = null;
URL url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection();
reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
System.out.println(urlString);
return reader;
}
And when server returns 503 – java throws Exception. But, how can I get text, that server return??
Use
getResponseCode()andgetResponseMessage()methods ofHttpURLConnectionclass.Invoke them after you have built the connection object but before you are getting stream from the connection.