2
我想用下面的一組代碼連接Paypal
,但是當我運行這個代碼時,我得到以下錯誤 - 。PayPal與java的集成
]
它正在與其他URL像谷歌。
在線程異常「主要」 javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路徑建設失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法找到有效的認證路徑請求的目標
代碼:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
@SuppressWarnings({ "deprecation" })
public class HttpURLConnectionExample {
public static void main(String[] args) throws UnsupportedOperationException, IOException {
@SuppressWarnings("unused")
final String USER_AGENT = "Mozilla/5.0";
boolean test = true;
String url = "";
url += (test)? "https://www.sandbox.paypal.com/cgi-bin/webscr?" : "https://www.paypal.com/cgi-bin/webscr?";
String ownerEmail="[email protected]";
url += "business=" + ownerEmail + "&";
url += "cmd=" + "_xclick" + "&";
url += "amount=" + "20.00" + "&";
url += "item_name=" + "user_signup" + "&";
url += "item_number=" + "item_number" + "&";
url += "quantity=" + "1" + "&";
url += "currency_code=" + "USD" + "&";
url += "no_shipping=" + "1" + "&";
url += "rm=" + "2";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
// add request header
request.addHeader("User-Agent", "Mozilla/5.0");
HttpResponse response = client.execute(request);
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " +
response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
System.out.println(result.toString());
}
}
我使用Apache Tomcat,請告訴我如何安裝證書 – anubhav
使用此步驟:https://www.digicert.com/ssl-certificate-installation-tomcat.htm –
此答案有幫助嗎?不要忘記評價這個問題 –