Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
AndroidHttpClient HttpGet with Basic Authorization
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ralph Bergmann | the4thFloor.eu  
View profile  
 More options Apr 1 2012, 2:25 pm
From: "Ralph Bergmann | the4thFloor.eu" <ra...@the4thfloor.eu>
Date: Sun, 01 Apr 2012 20:25:44 +0200
Local: Sun, Apr 1 2012 2:25 pm
Subject: AndroidHttpClient HttpGet with Basic Authorization
Hallo,

why I can't add a "Authorization" header field to my get request?

AndroidHttpClient client = AndroidHttpClient.newInstance(useragent);

HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 15 * 1000);
HttpConnectionParams.setSoTimeout(httpParams, 15 * 1000);

HttpGet get = new HttpGet(url);
get.addHeader("Authorization", "Base64 encoded String");
get.addHeader("Accept", "application/json");
get.setParams(httpParams);

...

When I execute this request I get a "HTTP/1.1 400 Bad Request" response.

When I remove the line "get.addHeader("Authorization", "Base64 encoded
String");" everything works fine (without the authorization).

What's going wrong? Is that the right way to do a basic authorization?
How to add the header field?

Ralph


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ralph Bergmann | the4thFloor.eu  
View profile  
 More options Apr 1 2012, 3:15 pm
From: "Ralph Bergmann | the4thFloor.eu" <ra...@the4thfloor.eu>
Date: Sun, 01 Apr 2012 21:15:00 +0200
Subject: Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization
found an example

http://www.android-dev-faq.com/2011/11/how-to-make-httpdigest-client....

Am 01.04.12 20:25, schrieb Ralph Bergmann | the4thFloor.eu:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolay Elenkov  
View profile  
 More options Apr 1 2012, 9:10 pm
From: Nikolay Elenkov <nikolay.elen...@gmail.com>
Date: Mon, 2 Apr 2012 10:10:43 +0900
Local: Sun, Apr 1 2012 9:10 pm
Subject: Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization
On Mon, Apr 2, 2012 at 4:15 AM, Ralph Bergmann | the4thFloor.eu

The implementation in Android is however broken: it uses a fixed nonce of 1.
If you server is actually checking for replay requests, you might get errors.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Banzon  
View profile  
 More options Apr 2 2012, 12:13 am
From: Michael Banzon <mich...@banzon.dk>
Date: Mon, 2 Apr 2012 06:13:42 +0200
Local: Mon, Apr 2 2012 12:13 am
Subject: Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization
You need to add "Basic" in front of the "Authorization" parameter (if
you are using basic auth.). The base64 encoded string also needs both
username and password.

This is from a working example:

method.addHeader("Authorization", "Basic " + Base64.encodeBytes(new
String(this.username + ":" + this.password).getBytes()));

The Base64.encodeBytes helper method is found here: http://iharder.net/base64

On Mon, Apr 2, 2012 at 3:10 AM, Nikolay Elenkov

--
Michael Banzon
http://michaelbanzon.com/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolay Elenkov  
View profile  
 More options Apr 2 2012, 12:22 am
From: Nikolay Elenkov <nikolay.elen...@gmail.com>
Date: Mon, 2 Apr 2012 13:22:19 +0900
Local: Mon, Apr 2 2012 12:22 am
Subject: Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization
On Mon, Apr 2, 2012 at 10:10 AM, Nikolay Elenkov

<nikolay.elen...@gmail.com> wrote:
> On Mon, Apr 2, 2012 at 4:15 AM, Ralph Bergmann | the4thFloor.eu
> <ra...@the4thfloor.eu> wrote:
>> found an example

>> http://www.android-dev-faq.com/2011/11/how-to-make-httpdigest-client....

> The implementation in Android is however broken: it uses a fixed nonce of 1.
> If you server is actually checking for replay requests, you might get errors.

This is, of course, for digest authentication. Basic authentication works, but
you should only use it over HTTPS.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolay Elenkov  
View profile  
 More options Apr 2 2012, 12:23 am
From: Nikolay Elenkov <nikolay.elen...@gmail.com>
Date: Mon, 2 Apr 2012 13:23:45 +0900
Local: Mon, Apr 2 2012 12:23 am
Subject: Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

On Mon, Apr 2, 2012 at 1:13 PM, Michael Banzon <mich...@banzon.dk> wrote:
> You need to add "Basic" in front of the "Authorization" parameter (if
> you are using basic auth.). The base64 encoded string also needs both
> username and password.

> This is from a working example:

> method.addHeader("Authorization", "Basic " + Base64.encodeBytes(new
> String(this.username + ":" + this.password).getBytes()));

There is really no need to re-implement functionality already found in
HttpClient.
(unless is broken, like the digest auth implementation)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Banzon  
View profile  
 More options Apr 2 2012, 12:54 am
From: Michael Banzon <mich...@banzon.dk>
Date: Mon, 2 Apr 2012 06:54:26 +0200
Local: Mon, Apr 2 2012 12:54 am
Subject: Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization
I am sure that Ralph will be absolutely ecstatic about that - can you
imagine that - a working example that require less code/library
inclusion compared to my app - absolutely magnificent!

Personally the first part ("working") would be my clear focus.

Have a nice day ;-)

On Mon, Apr 2, 2012 at 6:23 AM, Nikolay Elenkov

--
Michael Banzon
http://michaelbanzon.com/

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nikolay Elenkov  
View profile  
 More options Apr 2 2012, 1:30 am
From: Nikolay Elenkov <nikolay.elen...@gmail.com>
Date: Mon, 2 Apr 2012 14:30:03 +0900
Local: Mon, Apr 2 2012 1:30 am
Subject: Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

On Mon, Apr 2, 2012 at 1:54 PM, Michael Banzon <mich...@banzon.dk> wrote:
> I am sure that Ralph will be absolutely ecstatic about that - can you
> imagine that - a working example that require less code/library
> inclusion compared to my app - absolutely magnificent!

I didn't post the example, but I have to agree. It is indeed a lot
better, than having to include (or write your own) Base64
implementation just to re-invent a feature that is already
available and probably well tested. Magnificent indeed :)

> Personally the first part ("working") would be my clear focus.

working != good
working != maintainable

etc.

> Have a nice day ;-)

Thanks!

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »