0

这是我的代码。我没有使用 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 进行此调用时,它会给我一个适当的响应。没有配备做通信的服务是这样的吗?

4

1 回答 1

0

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

于 2013-08-01T21:16:52.537 回答