Java HTTP Response getResponseErrorContent(HttpURLConnection httpConn)

Here you can find the source of getResponseErrorContent(HttpURLConnection httpConn)

Description

Gets the error response as a string

License

Apache License

Parameter

Parameter Description
httpConn a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static String getResponseErrorContent(HttpURLConnection httpConn) throws IOException 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.HttpURLConnection;

public class Main {
    /**//w w w.ja  v  a  2s  .c  o  m
     * Gets the error response as a string
     * 
     * @param httpConn
     * @return
     * @throws IOException
     */
    public static String getResponseErrorContent(HttpURLConnection httpConn) throws IOException {
        if (httpConn.getErrorStream() == null) {
            return null;
        } else {
            StringBuilder sb = new StringBuilder();
            BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getErrorStream()));
            String str;
            while ((str = in.readLine()) != null) {
                sb.append(str + "\n");
            }
            in.close();

            return sb.toString();
        }
    }
}

Related

  1. getResponseAsString(HttpURLConnection conn)
  2. getResponseBody(HttpURLConnection conn)
  3. getResponseContent(HttpURLConnection connection)
  4. getResponseContent(HttpURLConnection httpConn)
  5. getResponseContent(String url)
  6. getResponseHeader(HttpURLConnection conn)
  7. getResponseHeader(String headerName, HttpURLConnection urlConnection)
  8. getResponseHeaders(URLConnection conn, HashMap headers)
  9. getResponseMessage(InputStream inputStream, HttpURLConnection connection)