Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Posts: 31
Registered: ‎06-12-2009
My Device: Not Specified

HTTP Authentication in browser field



I am facing a problem..I am unable to connect any site which asks for authentication through browser field...


I have tried






It connects fine when using BB Native browser...am I missing some thing ? Should there be some HTTP Authentication support that I have to set ? os should I have to add some additional request headers ?


How can this be achived using browser field in my application ?


Thank you.

BlackBerry Development Advisor
Posts: 15,882
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: HTTP Authentication in browser field

Note that the browser field samples included with the BlackBerry JDE have not implemented support for cookies, which would be required for most sites that require authentication.  Please refer to the following.


 How To – Enable cookies in BrowserField
Article Number: DB-00675


Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
New Contributor
Posts: 6
Registered: ‎02-26-2010
My Device: 8900 4.6.1
My Carrier: Digitel

Re: HTTP Authentication in browser field

Hi Mark.


Actually, I found a little issue in the "Enable Cookies in the BrowserField" example.


As you know, you are getting the Field content using getHeaderField(String key).


Well. Using the Browserfield for a very simple Facebook HTTP  login enabler, I receive the following headers for OAuth process:



HTTP/1.0 302 Found                                                                                              
Cache-Control: private, no-cache, no-store, must-revalidate                                                     
Content-Type: application/xhtml+xml; charset=utf-8                                                              
Expires: Sat, 01 Jan 2000 00:00:00 GMT                                                                          
Location: http://m.facebook.com/connect/uiserver.php?app_id=XXXXX&method=permissions.request&display=wa
P3P: CP="Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p"                                 
Pragma: no-cache                                                                                                
Set-Cookie: datr=PxXlTZUuW8o5Z4K69O3KaksD; expires=Thu, 30-May-2013 16:20:15 GMT; path=/; domain=.facebook.com; httponly                                                                                                         
Set-Cookie: lsd=n9lMs; path=/; domain=.facebook.com                                                             
Connection: close                                                                                               
Content-Length: 0


As you can see, there are two Set-Cookie keys in the headers. So, using the getHeaderField(String key). method, I'll get only the first key-ocurrence value, that is, I'll never handle the other cookie values.


The solution is obvlous, just replacing getHeaderField(String key) for getHeaderField(int index), as follows:




            for (int i = 0;(key = connection.getHeaderFieldKey(i)) != null; i++)
                if (key.equalsIgnoreCase("set-cookie"))
                    String cookieContent=connection.getHeaderField(i); //Instead connection.getHeaderField(key)





Hope this can help some programmers!




Anibal Itriago