【发布时间】:2013-07-10 16:01:15
【问题描述】:
当我们的密码很长时,我们遇到了 HttpURLConnection + 基本身份验证问题。
示例代码如下:
URL url = new URL("http://localhost/data.json");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(method);
String authString = clientId + ":" + clientSecret;
BASE64Encoder encoder = new BASE64Encoder();
String authHeader = encoder.encode(authString.getBytes());
conn.setRequestProperty("Authorization", authHeader);
conn.setRequestProperty("Accept", "application/json");
我们尝试使用
String authString = clientId + ":" + clientSecret;
authString = "" + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());
但运气不好。
具有特定长度密码的基本身份验证的 HttpURLConnection 可以正常工作,但使用冗长的密码时我们会遇到问题。并且返回的错误码是400
注意:这与 Login with Paypal 集成https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/#making-first-call有关
我们的示例代码(由 PayPal 提供)也无法正常工作。
提前谢谢你。
【问题讨论】:
-
响应是否包含除状态码 400 以外的任何内容?错误响应的正文通常会包含一条消息,提供有关错误的更多详细信息。