Best code examples for Java 8 HttpURLConnection class (java.net.HttpURLConnection)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 HttpURLConnection class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 HttpURLConnection examples from Open Source projects
This code example shows how to use the following methods: setRequestMethod, setRequestProperty, setSSLSocketFactory
      SSLContext context = SSLContext.getInstance("TLS");
      context.init(null, trustManagerFactory.getTrustManagers(), null);
 
      URL url = new URL(String.format("https://gcm.textsecure.whispersystems.org%s", urlFragment));
      HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
      connection.setSSLSocketFactory(context.getSocketFactory());
      connection.setRequestMethod(method);
      connection.setRequestProperty("Content-Type", "application/json");
 
      if (password != null) {
        System.out.println("Adding authorization header: " + getAuthorizationHeader());
        connection.setRequestProperty("Authorization", getAuthorizationHeader());
      } 
 
      return connection;
    } catch (NoSuchAlgorithmException e) {
      throw new AssertionError(e);
    } catch (KeyManagementException e) {
      throw new AssertionError(e);
    } catch (MalformedURLException e) {
Full Snippet Info
8
CodeRank
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, 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: getResponseCode, connect
            getAuthenticationHandlerConfiguration(true)); 
    auth.start();
    try { 
      URL url = new URL(auth.getBaseURL());
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.connect();
      Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
    } finally { 
      auth.stop();
    } 
  } 
 
  @Test 
  public void testAnonymousDisallowed() throws Exception { 
    AuthenticatorTestCase auth = new AuthenticatorTestCase();
    auth.setAuthenticationHandlerConfig(
            getAuthenticationHandlerConfiguration(false)); 
    auth.start();
    try { 
      URL url = new URL(auth.getBaseURL());
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResponseCode
     */ 
    @Override 
    public String toString() {
        String responseCode;
        try { 
            responseCode = String.format("%d", (connection != null) ? connection.getResponseCode() : 200);
        } catch (IOException e) {
            responseCode = "unknown";
        } 
 
        return new StringBuilder().append("{Response: ").append(" responseCode: ").append(responseCode)
                .append(", graphObject: ").append(graphObject).append(", error: ").append(error)
                .append(", isFromCache:").append(isFromCache).append("}")
                .toString();
    } 
 
    /** 
     * Indicates whether the response was retrieved from a local cache or from the server. 
     * 
     * @return true if the response was cached locally, false if it was retrieved from the server 
Full Snippet Info
7
CodeRank
Related Java 8 HttpURLConnection Questions & Answers:
Other Java 8 HttpURLConnection Examples
92:	            CommonUtilities.displayMessage(context, message);
93:	        } catch (IOException e) {
94:	            // At this point the device is unregistered from GCM, but still
95:	            // registered in the server.
96:	            // We could try to unregister again, but it is not necessary:
-
95:	            // registered in the server.
96:	            // We could try to unregister again, but it is not necessary:
97:	            // if the server tries to send a message to the device, it will get
98:	            // a "NotRegistered" error message and should unregister the device.
99:	            String message = context.getString(R.string.server_unregister_error,

Read More

66:	            Bitmap bitmap=null;
67:	            URL imageUrl = new URL(url);
68:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
69:	            conn.setConnectTimeout(30000);
70:	            conn.setReadTimeout(30000);
-
66:	            Bitmap bitmap=null;
67:	            URL imageUrl = new URL(url);
68:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
69:	            conn.setConnectTimeout(30000);
70:	            conn.setReadTimeout(30000);

Read More

65:	            URL imageUrl = new URL(url);
66:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
67:	            conn.setConnectTimeout(30000);
68:	            conn.setReadTimeout(30000);
69:	            conn.setInstanceFollowRedirects(true);
-
65:	            URL imageUrl = new URL(url);
66:	            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
67:	            conn.setConnectTimeout(30000);
68:	            conn.setReadTimeout(30000);
69:	            conn.setInstanceFollowRedirects(true);

Read More

See Code Examples for Java 8 HttpURLConnection Methods: