Best code examples for Java 8 HttpsURLConnection class (javax.net.ssl.HttpsURLConnection)

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

Java 8 HttpsURLConnection 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: setRequestMethod, setDoInput, setDoOutput, setRequestProperty, setUseCaches
		} 
		return new Request.Builder().source("com.apple.maps").unknown3(0).unknown4(0).wifis(wifis).build(); 
	} 
 
	private static void prepareConnection(HttpsURLConnection connection, int length) throws ProtocolException {
		connection.setRequestMethod("POST");
		connection.setDoInput(true);
		connection.setDoOutput(true);
		connection.setUseCaches(false);
		connection.setRequestProperty(HTTP_FIELD_CONTENT_TYPE, CONTENT_TYPE_URLENCODED);
		connection.setRequestProperty(HTTP_FIELD_CONTENT_LENGTH, String.valueOf(length));
	} 
 
	public Response retrieveLocations(String... macs) throws IOException {
		Request request = createRequest(macs);
		byte[] byteb = request.toByteArray();
		byte[] bytes = combineBytes(APPLE_MAGIC_BYTES, byteb, (byte) byteb.length);
		HttpsURLConnection connection = createConnection();
		prepareConnection(connection, bytes.length);
		OutputStream out = connection.getOutputStream();
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInputStream, setSSLSocketFactory
        "/echo?a=b&c<=d&e=>"))); 
  } 
 
  private static String readOut(URL url) throws Exception {
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory());
    InputStream in = conn.getInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyBytes(in, out, 1024);
    return out.toString();
  } 
 
} 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInputStream, getHostnameVerifier, setSSLSocketFactory
		   
		  //HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); 
		  //for now for testing 
		  HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		  HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection();
		  urlConnection.setSSLSocketFactory(sslContext.getSocketFactory());
		  Log.i(TAG,"hostnameverifier is: " + urlConnection.getHostnameVerifier().getClass().getName());
 
		  return urlConnection.getInputStream();
	} 
 
	public void onClick(View arg0) {
		try { 
			InputStream is = this.testHttpsUrlPinned();
			Log.i(TAG, "made SSL connection!");
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String line = null;
			while( (line = br.readLine()) != null){
				mTextView.append(line);
				Log.i(TAG,line);
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setInstanceFollowRedirects, setRequestMethod, getOutputStream, setAllowUserInteraction, setDoOutput
        try { 
            url = new URL(splunkUrl);
            connection = (HttpsURLConnection)url.openConnection();
 
            //make POST request 
            connection.setRequestMethod("POST");
            if (!authToken.equals("")) {
                connection.setRequestProperty("Authorization",
                        "Splunk " + authToken);
            } 
            connection.setDoOutput(true);
 
            //no caching, no user interaction, no redirects 
            connection.setUseCaches(false);
            connection.setAllowUserInteraction(false);
            connection.setInstanceFollowRedirects(false);
 
            //POST to the login endpoint 
            outputstreamwriter = new OutputStreamWriter(
                    connection.getOutputStream(), "UTF-8");

6
CodeRank
Related Java 8 HttpsURLConnection Questions & Answers:
See Code Examples for Java 8 HttpsURLConnection Methods: