如果我使用描述的Authentication OkHttpClient示例(页面末尾的https://github.com/square/okhttp/wiki/Recipes),我就成功了。但是,如果我尝试使用此方法对Bitbucket API (Version2,Cloud)进行身份验证,就会得到:
java.io.IOException: Unexpected code Response{protocol=http/1.1, code=403, message=FORBIDDEN, url=https://api.bitbucket.org/2.0/repositories/myuser/test/pullrequests}
我试过:
Request request = new Request.Builder()
.url("https://api.bitbucket.org/2.0/repositories/myuser/test/pullrequests")
.get()
.build();
如果我使用Curl代替,它会工作!-短版本:
String command = "curl -u myuser:mypass -X GET https://api.bitbucket.org/2.0/repositories/myuser/test/pullrequests");
p = Runtime.getRuntime().exec(command);
有什么建议吗?
发布于 2016-06-15 11:27:37
好吧-我明白了-我必须在每一个请求中添加第四次凭证:
final String login = "myuser";
final String password = "mypass";
String credential = Credentials.basic(login, password);
Request request = new Request.Builder()
.url("https://api.bitbucket.org/2.0/repositories/myuser/test/pullrequests")
.header("Authorization", credential)
.get()
.build();
https://stackoverflow.com/questions/37833928
复制相似问题