Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Nikolay Elenkov
On Mon, Apr 2, 2012 at 1:54 PM, Michael Banzon  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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Michael Banzon
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
 wrote:
> On Mon, Apr 2, 2012 at 1:13 PM, Michael Banzon  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 received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



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

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Nikolay Elenkov
On Mon, Apr 2, 2012 at 1:13 PM, Michael Banzon  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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Nikolay Elenkov
On Mon, Apr 2, 2012 at 10:10 AM, Nikolay Elenkov
 wrote:
> On Mon, Apr 2, 2012 at 4:15 AM, Ralph Bergmann | the4thFloor.eu
>  wrote:
>> found an example
>>
>> http://www.android-dev-faq.com/2011/11/how-to-make-httpdigest-client.html
>>
>
> 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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Michael Banzon
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
 wrote:
> On Mon, Apr 2, 2012 at 4:15 AM, Ralph Bergmann | the4thFloor.eu
>  wrote:
>> found an example
>>
>> http://www.android-dev-faq.com/2011/11/how-to-make-httpdigest-client.html
>>
>
> 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 received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



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

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Nikolay Elenkov
On Mon, Apr 2, 2012 at 4:15 AM, Ralph Bergmann | the4thFloor.eu
 wrote:
> found an example
>
> http://www.android-dev-faq.com/2011/11/how-to-make-httpdigest-client.html
>

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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Ralph Bergmann | the4thFloor.eu
found an example

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


Am 01.04.12 20:25, schrieb Ralph Bergmann | the4thFloor.eu:
> 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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] AndroidHttpClient HttpGet with Basic Authorization

2012-04-01 Thread Ralph Bergmann | the4thFloor.eu
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 received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en