質問

Most importantly I want to get the exceptionMessage that I am able to view as part of the data returned when I use SoapUI to make the request. I don't see anything in HttpURLConnection that includes this detailed information. Only responseCode and responseMessage, which are nice, but are lacking the description I'm looking for.

Also, does SoapUI parse this raw data into JSON and XML itself, or is there a simple way I can get it as JSON through java as well?

Thanks

役に立ちましたか?

解決

The server returns HTTP headers and in most cases a body. To get the body in case of a error, you have to do something like that:

InputStream is;    
if (conn.getResponseCode() / 100 == 2) { // HTTP status code 2xx, e.g. 200
    is = conn.getInputStream();

    // read input stream -> this is the content you wanted

} else {
    is = conn.getErrorStream();

    // read input stream -> contains a description of the error
    // depending on header "Content-Type" you can also parse the stream
    // as JSON or XML or HTML ...

}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top