Code example for HttpsURLConnection

Methods: disconnectgetContentLengthgetInputStreamsetDoInput

0
		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) {
 
			DataInputStream dis = new DataInputStream(conn.getInputStream());
 
			data = new byte[length];
 
			dis.readFully(data);
 
			dis.close();
 
			System.err.println(new String(data));
		} 
 
		conn.disconnect();
 
		// 验证 
		assertNotNull(data);
 
	} 
Stop searching for code, let great code find you!  Add Codota to your java IDE