Frage

I am trying to call HTTP request with network credential in blackberry. i have already implement on Java, Android it's working fine but not working on blackberry. Following step i have done in blackberry.

For set Network credential i have added three following jar.

  1. commons-codec-1.6.jar
  2. commons-httpclient-3.0.1.jar
  3. commons-logging-1.1.1.jar

add this jar files are in blackberry project.

Following sample Code that work fine in Core Java.

 try{
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod("http://www.google.com");
        get.setDoAuthentication( true );
        try {
            int status = client.executeMethod( get );
            System.out.println(status + "\n" + get.getResponseBodyAsString());

        } finally {
            get.releaseConnection();
        }
    }catch(Exception e){
        System.out.println("Error:>>>>>>"+e);
    }

Now there are not error on code but whenever try to click on application icon error face like "error starting appName: Module 'commons-httpclient-3.0.1' not found"

Can any one suggest what's this error say.

War es hilfreich?

Lösung

BB does not support HttpClient. But it does support J2ME's HttpConnection and is quite similar to HttpClient, so you can easily adjust with it. Here's some sample code to get you started:

try{
HttpConnection mConn = (HttpConnection)Connector.open(urlToPost);

mConn.setRequestMethod(HttpConnection.POST);
mConn.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
mConn.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
mConn.setRequestProperty("Content-Language", "en-CA");
//---------------------------------------------------
mConn.setRequestProperty("User",usr);
mConn.setRequestProperty("pass",pass);

//---------------------------------------------------
catch(Exception e){//---handle your exceptions---//}
} finally {
    mConn.close();//don't forget to close connections, only a limited number are available
}

This is a good article for beter understanding.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top