在项目过程中发现调用的接口地址为https形式的,一般用httpclient调用会抛出异常:Exception in thread "main" javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated,经过查找资料发现时因为https会使用SSL数字证书验证,而服务端并没有提供相应的SSL数字证书,这就需要在调用时绕过校验,具体实现代码如下:
1.httpclient
public static void main(String[] args) throws HttpException, IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient = wrapClient(httpclient);
HttpPost httppost = new HttpPost(url);
StringEntity myEntity = new StringEntity(test(), "utf-8");
httppost.addHeader("Content-Type", "text/html;charset=utf-8");