Note that there are some explanatory texts on larger screens.

plurals
  1. POHttp Post with Blackberry 6.0 issue
    text
    copied!<p>I am trying to post some data to our webservice(written in c#) and get the response. The response is in JSON format.</p> <p>I am using the Blackberry Code Sample which is BlockingSenderDestination Sample. When I request a page it returns with no problem. But when I send my data to our webservice it does not return anything. </p> <p>The code part that I added is : </p> <pre><code>ByteMessage myMsg = bsd.createByteMessage(); //myMsg.setStringPayload("I love my BlackBerry device!"); myMsg.setMessageProperty("querytpe","myspecialkey");//here is my post data myMsg.setMessageProperty("uname","myusername"); myMsg.setMessageProperty("pass","password"); ((HttpMessage) myMsg).setMethod(HttpMessage.POST); // Send message and wait for response myMsg response = bsd.sendReceive(myMsg); </code></pre> <p>What am i doing wrong? And what is the alternatives or more efficients way to do Post with Blackberry.</p> <p>Regards.</p> <p>Here is my whole code:</p> <pre><code>class BlockingSenderSample extends MainScreen implements FieldChangeListener { ButtonField _btnBlock = new ButtonField(Field.FIELD_HCENTER); private static UiApplication _app = UiApplication.getUiApplication(); private String _result; public BlockingSenderSample() { _btnBlock.setChangeListener(this); _btnBlock.setLabel("Fetch page"); add(_btnBlock); } public void fieldChanged(Field button, int unused) { if(button == _btnBlock) { Thread t = new Thread(new Runnable() { public void run() { Message response = null; String uriStr = "http://192.168.1.250/mobileServiceOrjinal.aspx"; //our webservice address //String uriStr = "http://www.blackberry.com"; BlockingSenderDestination bsd = null; try { bsd = (BlockingSenderDestination) DestinationFactory.getSenderDestination ("name", URI.create(uriStr));//name for context is name. is it true? if(bsd == null) { bsd = DestinationFactory.createBlockingSenderDestination (new Context("ender"), URI.create(uriStr) ); } //Dialog.inform( "1" ); ByteMessage myMsg = bsd.createByteMessage(); //myMsg.setStringPayload("I love my BlackBerry device!"); myMsg.setMessageProperty("querytpe","myspecialkey");//here is my post data myMsg.setMessageProperty("uname","myusername"); myMsg.setMessageProperty("pass","password"); ((HttpMessage) myMsg).setMethod(HttpMessage.POST); // Send message and wait for response myMsg response = bsd.sendReceive(myMsg); if(response != null) { BSDResponse(response); } } catch(Exception e) { //Dialog.inform( "ex" ); // process the error } finally { if(bsd != null) { bsd.release(); } } } }); t.start(); } } private void BSDResponse(Message msg) { if (msg instanceof ByteMessage) { ByteMessage reply = (ByteMessage) msg; _result = (String) reply.getStringPayload(); } else if(msg instanceof StreamMessage) { StreamMessage reply = (StreamMessage) msg; InputStream is = reply.getStreamPayload(); byte[] data = null; try { data = net.rim.device.api.io.IOUtilities.streamToBytes(is); } catch (IOException e) { // process the error } if(data != null) { _result = new String(data); } } _app.invokeLater(new Runnable() { public void run() { _app.pushScreen(new HTTPOutputScreen(_result)); } }); } } </code></pre> <p>..</p> <pre><code>class HTTPOutputScreen extends MainScreen { RichTextField _rtfOutput = new RichTextField(); public HTTPOutputScreen(String message) { _rtfOutput.setText("Retrieving data. Please wait..."); add(_rtfOutput); showContents(message); } // After the data has been retrieved, display it public void showContents(final String result) { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { _rtfOutput.setText(result); } }); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload