我正在尝试使用以下代码集连接 Paypal
,但是当我运行这段代码时,出现以下错误 - 。
]
它正在与其他 URL(如 google)一起使用。
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
代码:
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="mail2nkmishra-facilitator-1@gmail.com";
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());
}
}
最佳答案
您遇到的问题是您的 Web 服务器(如 apache、weblogic 等)没有安装 paypal 的证书,就像您的网络浏览器安装了证书一样。
即在 weblogic 中,您使用 keytool 安装证书,您可以在此站点中验证您的签名算法 sslLabs
这是 scan结果
关于java - Paypal 与java集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33301851/