我可以在普通的HTTPURLConnection
请求中设置身份验证标头,如下所示:
URL url = new URL(source);
HttpURLConnection connection = this.client.open(url);
connection.setRequestMethod("GET");
connection.setRequestProperty("Authorization", "Bearer " + token);
这是HttpURLConnection的标准。在上面的代码片段中,this.client
是 Square 的 OkHTTPClient
的实例(这里)。
我想知道是否有一种OkHTTP
特定的方法来设置身份验证标头?我看到了OkAuthenticator
类,但不清楚如何使用它或者它似乎只处理身份验证挑战。
感谢您提前提供任何指针。