Search code examples
javablackberryblackberry-simulator

Integrating Post Web Services in Blackberry app


I am very new Blackberry App Development and facing a big problem in integrating Web Services in my Blackberry app. I have to use Post Web Services in the Application and don't find even a single tutorial which explains how to integrate the Web services in Blackberry. Please some one help in this regard. I executed the example give at this link. Internet Avaialble when I try to open link Browser but it is not connecting to Web Services through my App.


Solution

  • try this -

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