HttpURLConnection getErrorStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for HttpURLConnection getErrorStream method.

This code example shows how to use the following methods:getErrorStream, setRequestMethod, connect, getInputStream, getOutputStream
	} 
 
	public static String doPost(URL url, InputStream stuffToPost, String contentType) throws IOException {
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		setUserAgent(conn);
		conn.setRequestMethod("POST");
		conn.setDoOutput(true);
		conn.setRequestProperty("connection", "close");
		if (contentType != null) {
			conn.setRequestProperty("Content-Type", contentType);
		} 
		OutputStream ostr = null;
		try { 
			ostr = conn.getOutputStream();
			copy(stuffToPost, ostr);
		} finally { 
			if (ostr != null)
				ostr.close();
		} 
 

6
CodeRank
This code example shows how to use the following methods:getContentEncoding, getErrorStream, getResponseCode, getInputStream
    public Response()  { 
    	 
    } 
    public Response(HttpURLConnection con) throws IOException {
        this.con = con;
        this.statusCode = con.getResponseCode();
        if(null == (is = con.getErrorStream())){
            is = con.getInputStream();
        } 
        if (null != is && "gzip".equals(con.getContentEncoding())) {
            // the response is gzipped 
            is = new GZIPInputStream(is);
        } 
    } 
 
    // for test purpose 
    /*package*/ Response(String content) {
        this.responseAsString = content;
    } 
 
7
CodeRank
This code example shows how to use the following methods:getErrorStream, getInputStream, setDoOutput, setRequestProperty
 
    JSONObject retrieveJSON( final URL url )
        throws IOException 
    { 
        final HttpURLConnection uc = (HttpURLConnection) url.openConnection();
        uc.setRequestProperty( "referer", referrer );
        uc.setDoOutput( false );
        try 
        { 
            return new JSONObject( IOUtil.toString( uc.getInputStream() ) );
        } 
        catch ( JSONException e )
        { 
            IOException ioe = new IOException( e.getMessage() );
            ioe.initCause( e );
            throw ioe;
        } 
        finally 
        { 
            uc.getInputStream().close();

6
CodeRank
This code example shows how to use the following methods:getErrorStream, getResponseCode, getResponseMessage, getHeaderField, getInputStream
	 * @throws IOException 
	 */ 
	protected InputStream getResponseStream(final HttpURLConnection request)
			throws IOException { 
		InputStream stream = getStream(request);
		int code = request.getResponseCode();
		updateRateLimits(request);
		if (isOk(code))
			return stream;
		else 
			throw createException(stream, code, request.getResponseMessage());
	} 
 
	/** 
	 * Get stream from request 
	 * 
	 * @param request 
	 * @return stream 
	 * @throws IOException 
	 */ 

7
CodeRank
This code example shows how to use the following methods:getContentEncoding, getErrorStream, getResponseCode, getInputStream
    private boolean streamConsumed;
 
 
    public Response(HttpURLConnection con) throws IOException {
        this.con = con;
        statusCode = con.getResponseCode();
        is = con.getErrorStream();
        if (null == is) {
            is = con.getInputStream();
        } 
        if (null != is && "gzip".equals(con.getContentEncoding())) {
            // the response is gzipped 
            is = new GZIPInputStream(is);
        } 
    } 
 
    // for test purposes 
    /*package*/ 
 
    protected Response() { } 
7
CodeRank
This code example shows how to use the following methods:getErrorStream, getResponseCode, getInputStream
        HttpsURLConnection connection = null;
        InputStream inputStream = null;
 
        try { 
            connection = connect(stringToURL(url), connection, doPost);
            if (connection.getResponseCode() < 400) { //no error
                inputStream = connection.getInputStream();
            } else { 
                inputStream = connection.getErrorStream();
            } 
            response = readFromStream(inputStream);
        } catch (Throwable e) {
            Log.e(TAG, Log.getStackTraceString(e));
            throw new BedditConnectionException(e.getMessage());
        } finally { 
            closeConnections(connection, inputStream);
        } 
 
        if (response.equals("")) {
            throw new BedditConnectionException("Empty response from Beddit"); 
6
CodeRank
This code example shows how to use the following methods:getErrorStream, getResponseCode, getResponseMessage, setRequestMethod, connect
	} 
 
	public static String doPost(URL url, InputStream stuffToPost, String contentType) throws IOException {
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		setUserAgent(conn);
		conn.setRequestMethod("POST");
		conn.setDoOutput(true);
		if (contentType != null) {
			conn.setRequestProperty("Content-Type", contentType);
		} 
		OutputStream ostr = null;
		try { 
			ostr = conn.getOutputStream();
			copy(stuffToPost, ostr);
		} finally { 
			if (ostr != null)
				ostr.close();
		} 
 
		conn.connect();

7
CodeRank
This code example shows how to use the following methods:getErrorStream, getResponseCode, getContentEncoding, getInputStream
    	this.method = method; 
    } 
     
    public Response(HttpURLConnection con) throws IOException { 
        this.con = con; 
        this.statusCode = con.getResponseCode(); 
        if(null == (is = con.getErrorStream())){ 
            is = con.getInputStream(); 
        } 
        if (null != is && "gzip".equals(con.getContentEncoding())) { 
            // the response is gzipped 
            is = new GZIPInputStream(is); 
        } 
    } 
 
    public int getStatusCode() { 
        return statusCode; 
    } 
 
    public String getResponseHeader(String name) { 
6
CodeRank
This code example shows how to use the following methods:disconnect, getErrorStream, getResponseCode, getContentType, getInputStream
			HttpURLConnection urlConnection = getHttpUrlConnection();
 
			try { 
				InputStream stream;
				try { 
					stream = new DoneHandlerInputStream(urlConnection.getInputStream());
				} catch (IOException exception) {
					stream = urlConnection.getErrorStream();
					if (stream == null) {
						throw exception;
					} 
					stream = new DoneHandlerInputStream(stream);
				} 
				JacksonManager.ContentType type = JacksonManager.ContentType.parse(urlConnection.getContentType());
 
				if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
					ObjectMapper mapper = JacksonManager.getMapper(type);
					throw Error.parse(mapper.readValue(stream, JsonNode.class));
				} 
 

6
CodeRank
This code example shows how to use the following methods:getContentEncoding, getErrorStream, getResponseCode, getInputStream
    public Response()  { 
    	 
    } 
    public Response(HttpURLConnection con) throws IOException {
        this.con = con;
        this.statusCode = con.getResponseCode();
        if(null == (is = con.getErrorStream())){
            is = con.getInputStream();
        } 
        if (null != is && "gzip".equals(con.getContentEncoding())) {
            // the response is gzipped 
            is = new GZIPInputStream(is);
        } 
    } 
 
    // for test purpose 
    /*package*/ Response(String content) {
        this.responseAsString = content;
    } 
 
6
CodeRank

Related HttpURLConnection getErrorStream Questions & Answers:

getErrorStream Method Overview
Returns an input stream from the server in the case of an error such as the requested file has not been found on the remote server.
See Code Examples for other Java 8 HttpURLConnection Methods: