尝试根据您的方案和情况使用验证器配置OkHttp3客户端:
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.authenticator(new Authenticator()
{
@Override
public Request authenticate(Route route, Response response) throws IOException
{
String credential = Credentials.basic("user", "pass");
return response.request().newBuilder()
.header("Authorization", credential)
.build();
}
})
.build();
然后,使用该客户端来形成您的Picasso对象,但是对于okhttp3,您必须使用OkHttp3Downloader,就像这样:
Picasso picasso = new Picasso.Builder(context)
.downloader(new OkHttp3Downloader(okHttpClient))
.build();
您可以从https://github.com/JakeWharton/picasso2-okhttp3-downloader获取OkHttp3Downloader。
Retrofit2.Builder()
有一个名为authorization
的属性,这可能是您要寻找的内容。 - yennsarahokhttp3
客户端的修改方式。 - yennsarah