【发布时间】:2013-08-02 16:06:33
【问题描述】:
这是我的代码。我没有使用 Maven 或 curl。
String encoding = Base64.encodeBase64String((clientId + ":" + clientSecret).getBytes());
encoding = encoding.replaceAll("\n", "");
URL url1 = new URL("https://api.sandbox.paypal.com/v1/oauth2/token");
HttpURLConnection conn = (HttpURLConnection) url1.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("grant_type", "client_credentials");
conn.setRequestProperty("Authorization", "Basic " + encoding);
System.out.println(conn.getResponseCode());
if (conn.getResponseCode() == 500) {
InputStream error = conn.getErrorStream();
BufferedReader er = new BufferedReader(new InputStreamReader(error));
String erLine;
while ((erLine = er.readLine()) != null) {
System.out.println(erLine);
}
}
InputStream content = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
conn.disconnect();
输出:
500 {"name":"INTERNAL_SERVICE_ERROR","information_link":"https://api.sandbox.paypal.com/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"023ff49775e72"}
问题:
好吧,当我使用 curl 进行此调用时,它会给我一个适当的响应。不具备通讯能力的服务是这样的吗?
【问题讨论】:
-
那么,您的代码块是用什么语言编写的?顺便说一句,很高兴
information_link它已经死了...... -
我正在使用 Java 进行编码。他们有一个 sdk 可以让我完成所有这些工作。但我试图避免在我的系统中安装 Maven。
-
您仍然可以在不使用 maven 的情况下使用 SDK。您可以在此处以 zip 格式下载 JAR plus 示例应用程序 paypal.github.io/#payments-tab-java
-
是的@Prasanna_Paypal,我让它与 SDK 一起工作。最后。谢谢。起初,我无法构建我的应用程序,可能是因为一些 jar 冲突。
标签: paypal paypal-sandbox