Authenticator.setDefault() with Fresco requests
See original GitHub issueHi I’m using Fresco to show images from a password-protected webservice. I’m setting the default authenticator for my http/https requests in my app’s onCreate like this:
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
userWebService, pwdWebService.toCharArray());
}
});
But everytime I call
SimpleDraweeView image = (SimpleDraweeView) findViewById(R.id.imageView_product);
GenericDraweeHierarchy h = image.getHierarchy();
h.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE);
image.setImageURI(uri);
the request is fired twice: the first fails the authentication (response 401) while the second authenticate correctly (response 200). I’m not 100% sure but I actually feel like it’s a Fresco issue since the code is really simple. Is anyone able to test this?
Thanks, Kind Regards.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Authenticator (Java Platform SE 7 ) - Oracle Help Center
All methods that request authentication have a default implementation that fails. Since: 1.2; See Also: setDefault(java.net.Authenticator) , ...
Read more >How to handle multiple Authenticator - Stack Overflow
Do I need to Authenticator.setDefault for each request ? This may not work if there are concurrent connection with mixed webservices... android.
Read more >Questions and Answers Authentication - TechDocs
The Question and Answer (QnA) authentication mechanism can either be used as a secondary authentication method for CA Auth ID Information, ...
Read more >Sentinels Rolling Archive User Access, Operations ...
the management of user requests and products publication to end users is managed by one DHuS instance called “Front-End”.
Read more >Overriding current java.net.Authenticator for specific requests
Authenticator.setDefault() if I want it to send its HTTP/HTTPS requests through a proxy that requires a username and a password.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
UPDATE: Actually seems like a bug of the native android network layer (HttpURLConnection). Previously I was doing this to initialize Fresco:
In this case, the agency that provide me the WebService form where I load my images told me they always see 2 requests for every image, the first without authentication header and the second correctly authenticated.
Then, thanks to @massimocarli’s post , I tried using OkHttp3 as network layer, implementing it like this:
And now it seems to work fine: only one authenticated request is fired.
I’m not closing this, I actually wait for a mod to close this so if there is a more technical consideration to do, it can be done.
Kind regards.
Great @Doomkyn, that is actually the solution that we usually suggest for this 😃
Thanks