java7訪問https Remote host closed connection during handshake
在使用new DefaultHttpClient(ClientConnectionManager clientConnectionManager)之前對clientConnectionManager進行初始化改造。
示例程式碼如下(重新定義一個DefaultHttpClient的子類。使用時new一個新的例項然後執行init方法,也可將初始化方法放在每個具體執行方法中):
public class HttpsUtil extends DefaultHttpClient {
public final static String HTTPGET = "GET";
public final static String HTTPPUT = "PUT";
public final static String HTTPPOST = "POST";
public final static String HTTPDELETE = "DELETE";
public final static String HTTPACCEPT = "Accept";
public final static String CONTENT_LENGTH = "Content-Length";
public final static String CHARSET_UTF8 = "UTF-8" ;
private static HttpClient httpClient;
public void init() throws Exception {
String base_Path = "/Users/jinx/Documents/jobs/git_mine/base/base";// 存放證書資料夾位置
String selfcertpath = base_Path + "ca.jks";//自身cert
String trustcapath = base_Path + "outgoing.CertwithKey.pkcs12"; //授信cert
KeyStore selfCert = KeyStore.getInstance("pkcs12");
selfCert.load(new FileInputStream(selfcertpath), Constant.SELFCERTPWD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
kmf.init(selfCert, Constant.SELFCERTPWD.toCharArray());
KeyStore caCert = KeyStore.getInstance("jks");
caCert.load(new FileInputStream(trustcapath), Constant.TRUSTCAPWD.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509");
tmf.init(caCert);
SSLContext sc = SSLContext.getInstance("TLSv1.2");//重點是這裡,JDK1.8使用TLS即可
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
SSLSocketFactory ssf = new SSLSocketFactory(sc, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", "埠", ssf));
httpClient = new DefaultHttpClient(ccm);
}
}
可能引入的包
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.KeyStore;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
相關推薦
java7訪問https Remote host closed connection during handshake
在使用new DefaultHttpClient(ClientConnectionManager clientConnectionManager)之前對clientConnectionManager進行初始化改造。 示例程式碼如下(重新定義一個DefaultH
java1.7訪問https Remote host closed connection during handshake
在使用new DefaultHttpClient(ClientConnectionManager clientConnectionManager)之前對clientConnectionManager進行初始化改造。 示例程式碼如下(重新定義一個DefaultHttpClient的子類。使用時new
FTPClient TLS 與 FTP 進行數據傳輸異常:Remote host closed connection during handshake
except cti 定義 sed pbs 8.0 java.net src same 環境:java JDK 1.8、org.apache.commons-net-3.6.jar、端口已放開 FTPClient ftpClient = new FTPClient(prot
java http 客戶端使用TSLv1.2[解決Remote host closed connection during handshake的問題]
1. jdk1.7預設是TSLv1, 但是可以支援TSLv1.1,TSLv1.2,jdk1.8預設是TSLv1.2 2.如果客服端是TSLv1,伺服器端設定是TSLv1.2,訪問會出現connection reset的錯誤. 3.既然jdk1.7可以支援TSLv1.2那麼肯定有辦法設定。網上
azkaban - Remote host closed connection during handshake和SSL peer shut down incorrectly報錯的解決方法
我使用azkan排程MapReduce程式,但是這個job執行失敗,然後我可能是強制關閉azkaban的服務,整個機器變得超級超級卡,我執行Linux命令變得很慢,我使用jps檢視程序,他孃的,好幾分鐘才出現,媽的,我窮得機器買不起貴的,所以太它孃的卡了。 我靠,嚇一跳 太恐怖了,
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake 痛苦解決之旅
上週另外一專案組的同事找到我說,遇到一個問題很棘手兩天了還沒解決掉,報錯如下: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at su
Remote host closed connection during handshake和SSL peer shut down incorrectly報錯的解決方法
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at com.sun.net.ssl.internal.ssl.SSLSoc
HtmlUnit報錯javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake的解決
採用HtmlUnit爬取網站資料的時候,在爬取某個https型別的網站的時候報錯:主要提示如下: javax.net.ssl.SSLHandshakeException: Remote host clo
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake異常處理記錄
1、修改Java\jre\lib\security\java.security檔案 crypto.policy=unlimited 2、增加配置 -Dhttps.protocols=TLSv1.1,TLSv1.2
javax.net.ssl.SSLHandshakeException: Remote host closed connection during han 報錯解決
javax.net.ssl.SSLHandshakeException: Remote host closed connection during han 北京某銀行信用卡網申開發團隊發來協助請求,內容是這樣的: 內網中應用伺服器要實現某一功能,需要從外網銀聯端獲取一段資
ssh連接提示 "Connection closed by remote host"
tail sdn edi who text 日誌 b2c closed blank 如果原來是可以用ssh連接的, 突然連接不上通常是連接數過多導致的. 解決方法一. 把SSH連接數改大 修改服務器上的這個文件:/etc/ssh/sshd_config 找到這行: #
使用命令登入不是預設埠的ftp server(Connection closed by remote host的原因)
如果登入的ftp server不是預設埠,在命令列中輸入: C:/Documents and Settings/yourname>ftp 172.28.1.1 Connected to 172.28.93.248. Connection closed by remote
ssh_exchange_identification: Connection closed by remote host 解決方法
share conn linux 註釋 etc all allow linu 執行 ssh_exchange_identification: Connection closed by remote host 解決方法問題描述:在linux主機上ssh 另一臺主機的內網地址報
SSH連線伺服器報ssh_exchange_identification: Connection closed by remote host
下午發現公司有臺圖片伺服器不能SSH遠端連線了,從內網的其它伺服器上ssh也不能連線,都是報:ssh_exchange_identification: Connection closed by remote host 眾所周知的原因,現在google搜尋不翻牆暫時用不了,用
Junipor交換機 ssh_exchange_identification: Connection closed by remote host
可根據以下步驟使其ssh服務恢復正常: Step1 check the files are present in the directory by login in to the switch and you should be in the shellroot@SUNNY
telnet: Unable to connect to remote host: Connection refused
環境: CentOS release 6.10 (Final) $ telnet 127.0.0.1 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused
telnet報“Unable to connect to remote host:Connection refused”錯誤
Linux下面telnet ip 埠號 報錯誤“Unable to connect to remote host:Connection refused”的時候,大部分是目標機的埠對應的服務宕掉了。 先用netstat -napt命令,看系統有沒有在監聽你telnet的埠號,若沒有對應的埠號,而該機器提供該
myBatis連接MySQL報異常:No operations allowed after connection closed.Connection was implicitly closed
csdn spa logs action env target details 默認 col 網站運行一個晚上,早上來上班,發現報錯: ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.M
使用curl,libcurl訪問Https
nat char 下載 them transport 編譯 -c osi 通過 編譯curl,libcurl 下載curl源碼(git clone https://github.com/curl/curl),在目錄curl\winbuild\BUILD.WINDOWS.tx
<Linux> Ubuntu error: ssh: connect to host master port 22: No route to host lost connection
ror host input ssh端口 linu 就會 accept ssh ubuntu iptables當找到匹配的規則時,就會執行相應的動作,而不會向下繼續匹配。因為ssh端口開放的規則在all規則之後,所以永遠都不會匹配到,也就是ssh永遠被禁止。 root下執行