https 协议,因为安全,所以在处理上,也有些不同。现在给出示例

     

    /**
    	 * @param url
    	 * @param xmlstring
    	 * @param match_id 密钥-- .p12的密钥
    	 * @param file "apiclient_cert.p12" .p12的文件路径
    	 * @return
    	 */
    	public static String httpsGetRequest(String url, String xmlstring, String match_id,String file){
    		    KeyStore keyStore;
    		    StringBuilder result = new StringBuilder();
    			try {
    				keyStore = KeyStore.getInstance("PKCS12");
    				FileInputStream instream = new FileInputStream(new File(file));
    	            keyStore.load(instream, match_id.toCharArray());
    
    		        // Trust own CA and all self-signed certs
    		        SSLContext sslcontext = SSLContexts.custom()
    		                .loadKeyMaterial(keyStore, match_id.toCharArray())
    		                .build();
    		        // Allow TLSv1 protocol only
    		        SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
    		                sslcontext,
    		                new String[] { "TLSv1" },
    		                null,
    		                SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    		        CloseableHttpClient httpclient = HttpClients.custom()
    		                .setSSLSocketFactory(sslsf)
    		                .build();
    		        try {
    
    	            HttpGet httpget = new HttpGet(url);
    	            System.out.println("executing request" + httpget.getRequestLine());
    	            CloseableHttpResponse response = httpclient.execute(httpget);
    	            try {
    	                HttpEntity entity = response.getEntity();
    	                System.out.println("----------------------------------------");
    	                System.out.println(response.getStatusLine());
    	                if (entity != null) {
    	                    System.out.println("Response content length: " + entity.getContentLength());
    	                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
    	                    String text="";
    	                    while ((text = bufferedReader.readLine()) != null) {
    	                    	result.append(text);
    	                    }
    	                }
    	                EntityUtils.consume(entity);
    	            } finally {
    	                response.close();
    	            }
    	        } finally {
    	            httpclient.close();
    	        }
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		return result.toString();
    	}
    	
    联系QQ:343886028 --加QQ群 145315854