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.

inside custom component

Native Development

Reply
Regular Contributor
jayakrishnan_salim
Posts: 61
Registered: ‎05-22-2011
My Device: Blackberry Torch
My Carrier: Airtel

Sending data over HTTP post in Cascades

Hi Everyone,

 

I am new to Cascades development. I am now learning how to code in Cascades for my next project. 

Can someone help me on how to send data (in bytes) over Http post in Cascades?

 

The requirement is like, I need to send data which is in JSON format to a web service. I saw few samples for accessing web content via GET method but I did not see a good example for POST method. 

 

Any help will be much appreciated. 

 

Thank you in advance. 

Please use plain text.
Developer
shahumang8
Posts: 599
Registered: ‎08-09-2010
My Device: Not Specified

Re: Sending data over HTTP post in Cascades

Hi,

 

 Please check below thread 

 

 http://supportforums.blackberry.com/t5/Cascades-Development/Sending-data-via-HTTP-post/m-p/2006789#M...

 

 

--------------------------------------------------------------------------------------------------------------------------------------------

feel free to press the like button on the right side to thank the user that helped you.

Please use plain text.
Developer
varghesekiran
Posts: 38
Registered: ‎09-27-2012
My Device: 9930
My Carrier: airtel

Re: Sending data over HTTP post in Cascades

Hi all.,

 

I have this same doubt..,please help me..,the link provided here is useful but it does not fill my need. I need to send a json request like this with http post.

{
   "username" : "my_username",
   "password" : "my_password",
   "validation-factors" : {
      "validationFactors" : [
         {
            "name" : "remote_address",
            "value" : "127.0.0.1"
         }
      ]
   }
}

 Please help me..,I couldn't find a useful tutorial in this...

 

Thanks in advance.

Please use plain text.
Contributor
ZuzooVn
Posts: 21
Registered: ‎09-18-2013
My Device: Z10
My Carrier: +

Re: Sending data over HTTP post in Cascades

Did you find the solution?

Please use plain text.
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Sending data over HTTP post in Cascades

[ Edited ]

Here is GET/POST example also

http://supportforums.blackberry.com/rim/board/message?board.id=Cascades&message.id=52007#M52007

 

@varghesekiran @ZuzooVn

I know of two options for creating JSON

 

First:

Use QVariant/QVariantMap/QVariantList

QVariantMap map; // username nad password
map.insert("username", "my_username");
map.insert("password", "my_password");

QVariantMap map2; // name and value
map2.insert("name", "remote_address");
map2.insert("value", "127.0.0.1");

QVariantList list; // [name and value]
list << map2; // append name and value

QVariantMap map3; // validationFactors
map3.insert("validationFactors", list);

map.insert("validation-factors", map3);

And now you need to serialize result (map) You can use external JSON library like a QtJson http://qjson.sourceforge.net or build in like JsonDataAccess

JsonDataAccess json;
QByteArray array;
json.saveToBuffer(map, &array); /* AND THE RESULT IS { "password" : "my_password", "username" : "my_username", "validation-factors" : { "validationFactors" : [ { "name" : "remote_address", "value" : "127.0.0.1" } ] } } */

Second: 

Or you can build it directly with QByteArray

QByteArray json;

json += "{"; // start brace
json += "\"username\": \"my_username\","; // username
json += "\"password\": \"my_password\","; // password
json += "\"validation-factors\": {";
json += "\"validationFactors\": [";
json += "{ \"name\": \"remote_address\",";
json += "\"value\": \"127.0.0.1\" } ] }";
json += "}"; // end brace

/* AND THE RESULT IS
{
   "password" : "my_password",
   "username" : "my_username",
   "validation-factors" : {
      "validationFactors" : [
         {
            "name" : "remote_address",
            "value" : "127.0.0.1"
         }
      ]
   }
}
*/

Hope it helps :Punk:



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Please use plain text.