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 –
此答案有帮助吗?不要忘记评价这个问题 –