Web sites that require security generally use HTTPS to encrypt requests and responses to transmissions. HTTPS can not be separated from the certificate, about the certificate is not said more. Apache's httpclient support HTTPS,
The following is an official sample program that uses the My.store file in the program.
This file is not a Web site certificate, but a certificate library containing your own password. This file needs to be generated by itself, and using the Keytool command in JDK makes it easy to generate my.store files. The steps are as follows (take Alipay for example):
Browser (for example, chrome) access to https://www.alipay.com/, click on the left side of the small lock, you can view Alipay's certificate information
The certificate information of the payment package is exported, the certificate format has many, der, CER and so on. Choose whatever you want.
command line or shell execution Keytool-import-alias "My Alipay cert"-file www.alipay.com.cert-keystore My.store,
If the Keytool command is not recognized, check to see if the JDK's environment variables are set correctly. "My Alipay cert" is an individual name, casually taken. The "Www.alipay.com.cert" file is the certificate of Alipay that was exported from the browser.
"My.store" is the build's own certificate library file. Carriage return execution, the effect is as follows:
OK, now you can execute the following code:
[Java] View plain copy package com.yeetrack.httpclient; /** * Created with IntelliJ IDEA. * User: victor * Date: 13-10-11 * Time: pm 3:09 * to change this template use File | Settings | File Templates. */ import java.io.File; import java.io.fileinputstream; import java.security.KeyStore; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.closeablehttpresponse; import org.apache.http.client.methods.httpget; import org.apache.http.conn.ssl.sslcontexts; import org.apache.http.conn.ssl.sslconnectionsocketfactory; import org.apache.http.impl.client.closeablehttpclient; import org.apache.http.impl.client.httpclients; import org.apache.http.util.entityutils; /** * code shows if you use Ssl context to create a secure socket connection */ public class ClientCustomSSL { public final staTic void main (String[] args) throws Exception { &nbs