【问题标题】:Integrating Post Web Services in Blackberry app在 Blackberry 应用程序中集成 Post Web 服务
【发布时间】:2013-04-22 17:43:32
【问题描述】:

我是一个非常新的黑莓应用程序开发人员,在我的黑莓应用程序中集成 Web 服务时遇到了一个大问题。我必须在应用程序中使用 Post Web 服务,甚至找不到解释如何在 Blackberry 中集成 Web 服务的教程。请有人在这方面提供帮助。我执行了这个link 给出的例子。当我尝试打开链接浏览器但它没有通过我的应用程序连接到 Web 服务时 Internet 可用。

【问题讨论】:

标签: java blackberry blackberry-simulator


【解决方案1】:

试试这个 -

try {
        httpURL="http://google.co.in/";

        if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
                && RadioInfo
                        .areWAFsSupported(RadioInfo.WAF_WLAN)) {
            httpURL += ";interface=wifi";
        }else  if (TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_BIS_B) && TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_BIS_B)) {
            System.out.println("BIS CONNECTION-------------------");
            // Holder.connectionInterface=";deviceside=false;ConnectionType=mds-public";
            httpURL += ";deviceside=false;ConnectionType=mds-public";
        } 
        //Dialog.alert(httpURL);
        HttpConnection httpConn;
        httpConn = (HttpConnection) Connector.open(httpURL);
        httpConn.setRequestMethod(HttpConnection.POST);
        DataOutputStream _outStream = new DataOutputStream(httpConn.openDataOutputStream());
        byte[] request_body = httpURL.getBytes();
        for (int i = 0; i < request_body.length; i++) {
            _outStream.writeByte(request_body[i]);
        }
        DataInputStream _inputStream = new DataInputStream(
        httpConn.openInputStream());
        StringBuffer _responseMessage = new StringBuffer();
        int ch;
        while ((ch = _inputStream.read()) != -1) {
            _responseMessage.append((char) ch);
        }
        String res = (_responseMessage.toString());
        responce = res.trim();

        //Dialog.alert(responce);

        httpConn.close();


    }catch (Exception e) {
        Dialog.alert("Error -"+e.toString());
    }

【讨论】:

  • 不必使用DataOutputStream _outStream = new DataOutputStream(httpConn.openDataOutputStream());。你可以使用DataOutputStream _outStream = httpConn.openDataOutputStream();
  • @Signare 我已经尝试了你的代码,我得到 java.io.InterruptedIOException:Local connection timed out after ~120000。通过看到上面的错误我们可以在它无法连接服务器但不明白为什么它没有连接的情况下。使用模拟器浏览器打开相同的 url 可以正常工作。
  • @Signare 不,我正在模拟器上进行测试,并且通过 LAN 连接到 Internet。
  • @Signare 非常感谢您帮助我们!
【解决方案2】:

发帖前请用“Blackberry+httppost”谷歌搜索,你会得到很多链接。 我也为您推荐一个对初学者有用的链接。这听起来不错。

您还必须研究“interface=wifi;deviceside=true”等连接扩展。

http://randywestergren.com/?p=191

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    相关资源
    最近更新 更多