Paypal Rest服务 - 响应:内部服务错误

时间:2013-08-01 16:02:38

标签: paypal paypal-sandbox

这是我的代码。我没有使用Maven或卷曲。

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 { “名称”: “INTERNAL_SERVICE_ERROR”, “information_link”: “https://api.sandbox.paypal.com/docs/api/#INTERNAL_SERVICE_ERROR”, “debug_id”: “023ff49775e72”}

问题:

好吧,当我使用curl进行此调用时,它会给我一个适当的响应。没有配备通信服务的是这种方式吗?

1 个答案:

答案 0 :(得分:0)

您可以打印Authorization标题并检查它是否正确填充?如果您的Authorization标头为空(我们将更改为显然返回更合适的错误),我们当前正在返回HTTP500。