Here you can find the source of getResponseStream(HttpURLConnection conn)
Parameter | Description |
---|---|
conn | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
static InputStream getResponseStream(HttpURLConnection conn) throws IOException
//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); } }