答案-3 谢谢.解决方案尝试使用身份验证器配置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-获取OkHttp3Downloader下载器 I am using picasso 2.5.2 library to download bitmap from remote server, the image url requires basic authentication in header.i have tried the following SO ansers but none of them work with the latest picasso and OkHttp libraries.Answer - 1Answer - 2Answer - 3Thanks in advance. 解决方案 Try configuring an OkHttp3 client with authenticator, depending on your scheme and situation: 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();Then, use that client in forming your Picasso object, but with okhttp3 you will have to use a OkHttp3Downloader instead, like so: Picasso picasso = new Picasso.Builder(context) .downloader(new OkHttp3Downloader(okHttpClient)) .build();You can get the OkHttp3Downloader from https://github.com/JakeWharton/picasso2-okhttp3-downloader 这篇关于如何使用OkHttp 3.2.0在Picasso 2.5.2中添加基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-26 06:37