Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

BlackBerry Push Development

Reply
New Contributor
Medvozaec
Posts: 5
Registered: ‎03-20-2012
My Carrier: T Mobile

Not working POST request from app to server over http protocol

Hello everyone!

 

Currently we are developing simple application that will receive push notifications but first we need to subscribe user through "post" request with device's id sending it from device to our CMS.

 

I know we need to whitelabel our application first to send anything via BIS over http. But we faced strange problem using WiFi connection: it is working fine on simulator and one of our test device and I see new devices subscribed but request doesn't working on some other devices.

 

Have anyone a idea what can prevent "post" or "get" request sending over stable WiFi connection on device with disabled BIS without any SIM? I think about certificates, wrong servicebook. may be something else??

 

I've read a lot of threads here but haven't found any useful information. 
Thanks in advance! 

Please use plain text.
New Contributor
Medvozaec
Posts: 5
Registered: ‎03-20-2012
My Carrier: T Mobile

Re: Not working POST request from app to server over http protocol

post request call:

 

URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false);
encPostData.append("deviceId", ""+DeviceInfo.getDeviceId());
encPostData.append("campaignId", campaign.getId());
cl.postRequest("addCampaignForDevice", encPostData);

 request source:

 

[CODE]
public String postRequest(String command, final URLEncodedPostData encPostData)
{
        InputStream is = null;
        OutputStream os = null;
        final String ur = "http://www.site.com/notifications/"+command;
     factory = new MyConnectionFactory();
        factory.setConnectionAttemptListener(this);
        Thread t = new Thread(new Runnable()
        {
            public void run()
            {
                ConnectionDescriptor cd = factory.getConnection(ur);
                if(cd != null)
                {
                    c = (HttpConnection) cd.getConnection();
                }
             }
        });
        t.start();
     while(c == null)
        {
         try{ Thread.sleep(50); }catch(Exception ex){}
        }
        try
        {
            byte[] postData = encPostData.toString().getBytes();
     c.setRequestMethod(HttpConnection.POST);
            c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            c.setRequestProperty("Content-Length", String.valueOf(postData.length));
            os = c.openOutputStream();
            os.write(postData);
            os.flush();
            is = c.openInputStream();
       StringBuffer bos = new StringBuffer();
            byte[] responseData = new byte[1024];
     int len;
            while ((len = is.read(responseData)) > 0)
            {
             bos.append(new String(responseData, 0, len));
            }
            is.close();
            final JSONObject json = new JSONObject(bos.toString());
            final String resp = json.getString("response");
            if(resp.equals("success")){}
            else
            {
          if (UiApplication.isEventDispatchThread()) {
        Dialog.inform("Post to notofication service failed. "+resp);
          } else {
           UiApplication.getUiApplication().invokeLater(new Runnable() {
                  public void run() {
                   try{
                    Dialog.inform("Post to notofication service failed. "+json.getString("message")+" \n "+encPostData.toString());
                   }catch(Exception ex)
                   {
                    Dialog.inform("Post to notofication service failed. Can not parse error!!!");
                   }
                  }
              });
          }  
           }
          return bos.toString();
   } catch (final Exception e)
   {
  e.printStackTrace();
   }
          return null;
}
[/CODE]

Please use plain text.