HttpURLConnection disconnect - 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 disconnect method.

This code example shows how to use the following methods:disconnect, getResponseCode, setChunkedStreamingMode, setRequestMethod, getOutputStream
This code example shows how to use the following methods:disconnect, getResponseCode, connect
 
    private void checkWsdl(URL wsdlURL) throws IOException {
        System.setProperty("http.keepAlive", "false");
        HttpURLConnection connection = (HttpURLConnection) wsdlURL.openConnection();
        try { 
            connection.connect();
            Assert.assertEquals(200, connection.getResponseCode());
        } finally { 
            connection.disconnect();
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:disconnect, getResponseCode, connect, setRequestProperty
    URLConnection conn = url.openConnection();
    if (!(conn instanceof HttpURLConnection)) {
      throw new IOException();
    } 
    HttpURLConnection connection = (HttpURLConnection) conn;
    connection.setRequestProperty("Accept", contentTypes);
    connection.setRequestProperty("Accept-Charset", "utf-8,*");
    connection.setRequestProperty("User-Agent", "ZXing (Android)");
    try { 
      try { 
        connection.connect();
      } catch (NullPointerException npe) {
        // this is an Android bug: http://code.google.com/p/android/issues/detail?id=16895 
        Log.w(TAG, "Bad URI? " + uri);
        throw new IOException(npe);
      } catch (IllegalArgumentException iae) {
        // Also seen this in the wild, not sure what to make of it. Probably a bad URL 
        Log.w(TAG, "Bad URI? " + uri);
        throw new IOException(iae);
      } 

10
CodeRank
This code example shows how to use the following methods:disconnect, setRequestMethod, connect, getInputStream, setConnectTimeout
6
CodeRank
This code example shows how to use the following methods:disconnect, getResponseCode, getResponseMessage, setRequestMethod, connect
        List<String> expectedPhrases = Arrays.asList(
                Response.Status.BAD_REQUEST.getReasonPhrase(), Response.Status.NOT_FOUND.getReasonPhrase()); 
 
        final URL url = new URL(getBaseUri().toString() + "^");
        final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
 
        connection.connect();
 
        final int statusCode = connection.getResponseCode();
        final String statusMessage = connection.getResponseMessage();
 
        connection.disconnect();
 
        assertTrue("Wrong response status code: " + statusCode,
                expectedCodes.contains(statusCode));
        assertTrue("Wrong response status reason: " + statusMessage,
                expectedPhrases.contains(statusMessage));
    } 
} 
8
CodeRank
This code example shows how to use the following methods:disconnect, setFixedLengthStreamingMode, getInputStream, getOutputStream, setDoOutput
6
CodeRank
This code example shows how to use the following methods:disconnect
 
    @Override 
    protected void closeConnection(HttpRequest request, HttpResponse response) {
        HttpURLConnection connection = (HttpURLConnection) request.unwrap();
        if (connection != null) {
            connection.disconnect();
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:disconnect, getResponseCode, getInputStream
	private String testURL(int exp, String urlStr) throws MalformedURLException, IOException {
		HttpURLConnection conn = null;
		try { 
			URL url = new URL(urlStr);
			conn = (HttpURLConnection) url.openConnection();
			int code = conn.getResponseCode();
			assertEquals(exp, code);
			if (exp != 200) {
				return null; 
			} 
			InputStream in = conn.getInputStream();
			byte[] data = IOUtil.readAll(in);
			return new String(data, "UTF-8");
		} finally { 
			if (conn != null) {
				try { 
					conn.disconnect();
				} catch (Exception e) {
					LOG.error("error closing", e);
				} 

6
CodeRank
This code example shows how to use the following methods:disconnect, getInputStream
This code example shows how to use the following methods:disconnect, getResponseCode, setRequestMethod, setConnectTimeout
        HttpURLConnection httpCon = null;
        int responseCode = -1;
        try { 
            URL url = new URL(endpoint + "?" + params);
            httpCon = (HttpURLConnection) url.openConnection();
            httpCon.setConnectTimeout(connectionTimeOut);
            httpCon.setRequestMethod("DELETE");
            responseCode = httpCon.getResponseCode();
        } catch (Exception e) {
            log.error("Failed to get the response " + e);
            throw new Exception("Failed to get the response :" + e);
        } finally { 
            if (httpCon != null) {
                httpCon.disconnect();
            } 
        } 
        Assert.assertEquals(responseCode, 202, "Response Code not 202");
    } 
 
    public void post(String endpoint, String params) throws Exception {
6
CodeRank

Related HttpURLConnection disconnect Questions & Answers:

Other HttpURLConnection disconnect Examples

113:	    private static void post(String endpoint, Map<String, String> params)
114:	            throws IOException {   	
115:	        
116:	        URL url;
117:	        try {

Read More

disconnect Method Overview
Releases this connection so that its resources may be either reused or closed.
See Code Examples for other Java 8 HttpURLConnection Methods: