首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >JAVA OkHttpClient身份验证器不适合我使用Bit斗API

JAVA OkHttpClient身份验证器不适合我使用Bit斗API
EN

Stack Overflow用户
提问于 2016-06-15 11:17:51
回答 1查看 120关注 0票数 0

如果我使用描述的Authentication OkHttpClient示例(页面末尾的https://github.com/square/okhttp/wiki/Recipes),我就成功了。但是,如果我尝试使用此方法对Bitbucket API (Version2,Cloud)进行身份验证,就会得到:

代码语言:javascript
运行
复制
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}

我试过:

代码语言:javascript
运行
复制
Request request = new Request.Builder()
.url("https://api.bitbucket.org/2.0/repositories/myuser/test/pullrequests")
.get()
.build();

如果我使用Curl代替,它会工作!-短版本:

代码语言:javascript
运行
复制
    String command = "curl -u myuser:mypass -X GET https://api.bitbucket.org/2.0/repositories/myuser/test/pullrequests");
    p = Runtime.getRuntime().exec(command);

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-15 11:27:37

好吧-我明白了-我必须在每一个请求中添加第四次凭证:

代码语言:javascript
运行
复制
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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37833928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档