Java HTTP Response getResponseStream(HttpURLConnection conn)

Here you can find the source of getResponseStream(HttpURLConnection conn)

Description

Returns the body of the response.

License

BSD License

Parameter

Parameter Description
conn a parameter

Exception

Parameter Description
IOException an exception

Declaration

static InputStream getResponseStream(HttpURLConnection conn) throws IOException 

Method Source Code


//package com.java2s;
/* Copyright (c) 2013, HotDocs Limited
   Use, modification and redistribution of this source is subject
   to the New BSD License as set out in LICENSE.TXT. */

import java.io.IOException;
import java.io.InputStream;

import java.net.HttpURLConnection;

public class Main {
    /**//from  w  w w .  j  a va  2  s .c  o  m
     * Returns the body of the response.
     * 
     * @param conn
     * @return
     * @throws IOException
     */
    static InputStream getResponseStream(HttpURLConnection conn) throws IOException {
        return httpOk(conn) ? conn.getInputStream() : conn.getErrorStream();
    }

    /**
     * Determines whether an HTTP request was successful.
     * 
     * @param status
     * @return
     * @throws IOException
     */
    static boolean httpOk(HttpURLConnection conn) throws IOException {
        // Is the response code >= 200 and < 300?
        return (conn.getResponseCode() / 100 == 2);
    }
}

Related

  1. getResponseHeader(HttpURLConnection conn)
  2. getResponseHeader(String headerName, HttpURLConnection urlConnection)
  3. getResponseHeaders(URLConnection conn, HashMap headers)
  4. getResponseMessage(InputStream inputStream, HttpURLConnection connection)
  5. getResponseStream(final HttpURLConnection connection)
  6. getResponseStringFromConn(HttpURLConnection conn, boolean isSuccess)
  7. getResponseText(URL constructedUrl, String encoding)
  8. getResposeText(HttpURLConnection connection)
  9. readResponse(HttpURLConnection conn, String encoding)