Java 8 HttpsURLConnection - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 HttpsURLConnection class.

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) {
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();
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();
  } 
 
} 
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);
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
This code example shows how to use the following methods:setRequestMethod, setDoOutput, setRequestProperty, setSSLSocketFactory
            throw new DataBoxException(message);
        } 
    } 
 
    private void configure(HttpsURLConnection connect) throws ProtocolException {
        connect.setSSLSocketFactory(socketFactory);
        // connect.setRequestProperty("Authorization", authorization); 
        connect.setRequestProperty("Authorization", authorization);
        // connect.setRequestProperty("Cookie", authCookie); 
        connect.setRequestMethod("POST");
        connect.setDoOutput(true);
        connect.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        connect.setRequestProperty("Soapaction", "");
    } 
 
    private void close(HttpsURLConnection con) {
        if (con != null) {
            con.disconnect();
        } 
    } 
6
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, getContentLength, getInputStream, setDoInput
		HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
 
		// conn.setRequestMethod(method); 
 
		// 打开输入输出流 
		conn.setDoInput(true);
		// conn.setDoOutput(true); 
 
		// 为HttpsURLConnection配置SSLSocketFactory 
		HTTPSCoder.configSSLSocketFactory(conn, password, keyStorePath,
				trustStorePath);
 
		// 鉴别内容长度 
		int length = conn.getContentLength();
 
		byte[] data = null;
 
		// 如果内容长度为-1,则放弃解析 
		if (length != -1) {
 

6
CodeRank
This code example shows how to use the following methods:getCipherSuite, getLocalCertificates, getLocalPrincipal, getPeerPrincipal, getServerCertificates
This code example shows how to use the following methods:disconnect, getContentLength, getInputStream, setDoInput
		HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
 
		// conn.setRequestMethod(method); 
 
		// 打开输入输出流 
		conn.setDoInput(true);
		// conn.setDoOutput(true); 
 
		// 为HttpsURLConnection配置SSLSocketFactory 
		HTTPSCoder.configSSLSocketFactory(conn, password, keyStorePath,
				trustStorePath);
 
		// 鉴别内容长度 
		int length = conn.getContentLength();
 
		byte[] data = null;
 
		// 如果内容长度为-1,则放弃解析 
		if (length != -1) {
 

6
CodeRank

Related Java 8 HttpsURLConnection Questions & Answers:

See Code Examples for Java 8 HttpsURLConnection Methods: