Welcome!

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

Java Development

Reply
Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320
Accepted Solution

Blackberry BrowserField: How to get the value of existing cookie

[ Edited ]

Hi,

 

First of all, i want to let you know I create a webpage at www.mydomain.com/whois.html

then i set a cookie with javascript named "username=adrian" on that page

 

In my BB Aplication i declare browserfield to load "whois.html"

 

Here's the code

 

    import  net.rim.device.api.browser.field2.BrowserFieldCookieManager;
    import net.rim.device.api.browser.field2.BrowserFieldConfig;
    import net.rim.device.api.browser.field2.BrowserField;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.container.MainScreen;

    public final class BrowserDemoScreen extends MainScreen
    {
    public BrowserDemoScreen()
    {
        setTitle("BrowserFieldScreen");

        BrowserFieldConfig config = new BrowserFieldConfig();
        config.setProperty(BrowserFieldConfig.USER_AGENT, "MyApplication 1.0");
        BrowserField _bf2 = new BrowserField(config);

        _bf2.requestContent("http://www.mydomain.com/whois.html");
        String cookie = _bf2.getCookieManager().getCookie("http://www.mydomain.com").valueOf("username");

        Dialog.alert("Cookie1 value = " + cookie);
        add(_bf2);
    }
    }

 

and if i run the code it doesn't get the value of  "username", what's wrong with my code? thank you

 

Please use plain text.
Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320

Re: Blackberry BrowserField: How to get the value of existing cookie

actually i can do this with java code fifteen years ago :smileyvery-happy: but if the question is very dificult to answer, just skip it i'll find another way to read value from a webpage..

Please use plain text.
Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320

Re: Blackberry BrowserField: How to get the value of existing cookie

[ Edited ]

or ...should i use HttpConnection instead of BrowserField?

 

test it..

 

import javax.microedition.io.HttpConnection;

tried to instantiate HttpConnection

 

HttpConnection conn=new HttpConnection();

 

and BANG!! got the error message

"Cannot instantiate the type HttpConnection"

 

*ffiuuhh.. this gonna be a long process...

 

Please use plain text.
Contributor
netrevolver
Posts: 31
Registered: ‎03-15-2013
My Device: 9320

Re: Blackberry BrowserField: How to get the value of existing cookie

aaah... i should point the cookie manager to mydomain.com/whois.html instead of mydomain.com it prints all information in "add(new RichTextField(existingCookie));"

Please use plain text.