【发布时间】:2013-07-07 13:17:17
【问题描述】:
我可以在正常的HTTPURLConnection 请求上设置 Auth Header,如下所示:
URL url = new URL(source);
HttpURLConnection connection = this.client.open(url);
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Bearer " + token);
这是 HttpURLConnection 的标准。在上面的代码中,sn -p this.client 是 Square 的 OkHTTPClient (here) 的一个实例。
我想知道是否有 OkHTTP 特定的方式来设置 Auth Header?我看到了 OkAuthenticator 类,但不清楚如何准确使用它/看起来它只处理身份验证挑战。
提前感谢您的任何指点。
【问题讨论】:
标签: java android oauth httpurlconnection