का उपयोग कर रहा पता निम्नलिखित करने के लिए एक अनुरोध भेजने के लिए कोशिश कर रहा हूँ प्रमाण पत्र की अनदेखी करने की आवश्यकता है। प्रमाण पत्र मान्य नहीं है और मैं इसे अनदेखा करना चाहता हूं। मैंने 1, 2 पर अपने शोध के आधार पर निम्नलिखित कोड लिखा लेकिन मैं इसे पूरा करने में सक्षम नहीं हूं। मैं जावा 1.7,जब restTemplate
https://api.stubhubsandbox.com/search/catalog/events/v3
कोड का उपयोग कर रहा
बातें jdk6 के बाद बदल गया है, लेकिन पिछली बार मैं यह करने के लिए कोशिश कर रहा था हम की कुंजी संग्रह करने के लिए एसएसएल प्रमाणपत्र आयात करने की जरूरतprivate static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers(){
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType){}
public void checkServerTrusted(X509Certificate[] certs, String authType){}
public void checkClientTrusted(
java.security.cert.X509Certificate[] arg0, String arg1)
throws CertificateException {
// TODO Auto-generated method stub
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] arg0, String arg1)
throws CertificateException {
// TODO Auto-generated method stub
}
}
};
public static void main(String[] args) {
TrustStrategy acceptingTrustStrategy =
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);
String url = "https://api.stubhubsandbox.com/search/catalog/events/v3";
RestTemplate rest = new RestTemplate();
Map<String, String> mvm = new HashMap<String, String>();
mvm.put("Authorization", "Bearer TOKEEEEEEEN");
Object object = rest.postForObject(url, null, Object.class, mvm);
System.err.println("done");
}
मैं 'UNQUESTIONING_TRUST_MANAGER' के लिए सेटिंग से चूक जाएं आपके कोड में 'SSLContext'। –
@MichalFoksa इसे कैसे सेट करें? इसके अलावा मेरे पास jdk 1.7 है लेकिन मेरे कोड का हिस्सा 1.8 यह सुनिश्चित नहीं है कि इसे कैसे ठीक किया जाए। –
आप 'RestTemplate' उदाहरण को 'RestTemplate restTemplate = new RestTemplate (requestFactory) पर स्व-हस्ताक्षरित प्रमाणपत्र स्वीकार करने के लिए मजबूर कर रहे हैं; '। लेकिन फिर आपके पास 'RestTemplate rest = new RestTemplate() है; rest.postForObject (यूआरएल, शून्य, ऑब्जेक्ट.क्लास, एमवीएम); '। इसका अर्थ यह है कि वास्तविक REST कॉल 'RestTemplate' उदाहरण का उपयोग करता है जो स्वयं हस्ताक्षरित प्रमाणपत्र स्वीकार नहीं करता है। यदि आप इसके बजाय 'restTemplate.postForObject' का उपयोग करते हैं, तो आपकी कॉल के माध्यम से जाना होगा। – manish