在黑莓中发送带有凭据的 HTTP 请求

发布于 2025-01-06 16:56:33 字数 895 浏览 4 评论 0原文

我正在尝试在黑莓中使用网络凭据调用 HTTP 请求。我已经在 J​​ava、Android 上实现了,它工作正常,但在黑莓上不起作用。以下步骤是我在黑莓中完成的。

为了设置网络凭据,我添加了以下三个 jar。

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

添加此 jar 文件位于黑莓项目中。

以下示例代码在 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);
    }

现在代码上没有错误,但每当尝试单击应用程序图标时都会出现错误,例如“启动 appName 时出错:未找到模块‘commons-httpclient-3.0.1’”

任何人都可以建议这个错误是什么意思。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2025-01-13 16:56:33

BB 不支持HttpClient。但它确实支持J2ME的HttpConnection并且与HttpClient非常相似,因此您可以轻松地使用它进行调整。下面是一些示例代码,可帮助您入门:

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
}

是一篇很好的文章,可以帮助您更好地学习理解。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文