Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpRequestInterceptor in AndroidHttpClient. I'm confused!

Tags:

android

http

I'm using AndroidHttpClient in my app. Now I need to use Basic authorization for requests.

http://developer.android.com/reference/android/net/http/AndroidHttpClient.html

In documentation they say I can use HttpRequestInterceptor but I can't figure HOW I can do that. There is no method to add this interceptor. Ideally I wanted to add it like they do here: http://dlinsin.blogspot.com/2009/08/http-basic-authentication-with-android.html

Anyone knows why it doesn't work for me or Google documentation wrong?

like image 458
katit Avatar asked Feb 04 '26 20:02

katit


2 Answers

Ok, it's not possible and obviously documentation wrong.. Had to go with plain HttpClient to get it to work.

like image 125
katit Avatar answered Feb 06 '26 12:02

katit


I know the question is old but for the benefit of anyone stumbling on this (like I did), you can roll the header yourself with HttpGet object. Like so :

httpGet.addHeader("Authorization", "Basic " + Base64.encode(username+":"+password));
like image 32
Saad Farooq Avatar answered Feb 06 '26 12:02

Saad Farooq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!