在Blackberry应用程序中集成Post Web Services

时间:2013-04-06 07:28:31

标签: java blackberry blackberry-simulator

我是一个非常新的Blackberry App Development,在我的Blackberry应用程序中集成Web服务面临着一个大问题。我必须在应用程序中使用Post Web Services,甚至找不到一个解释如何在Blackberry中集成Web服务的教程。请在这方面帮助一些人。我在此link执行了示例。当我尝试打开链接浏览器但未通过我的应用程序连接到Web服务时,Internet Avaialble。

2 个答案:

答案 0 :(得分:3)

试试这个 -

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());
    }

答案 1 :(得分:2)

发布之前请谷歌用“黑莓+ httppost”你会得到很多链接。 同样适合你我建议一个对初学者有用的链接。这听起来不错。

此外,您还必须学习连接扩展,例如“interface = wifi; deviceside = true”等。

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