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
Contributor
dhiraj_n
Posts: 24
Registered: ‎11-11-2013
My Device: BB 10 -BlackBerry Z10

Re: Working with HTTP

Here I have used hardcode parameters to post ---

 

postParameters ="str=<req><IMEI>A1000026533AE4</IMEI><OS>2.3.3</OS><Provider>cricKet</Provider><NType>CDMA</NType><Num>ODQzOTI2NDM4Nw==</Num><Device>Android%20unknown%20ADR3010</Device><Version>1.1.9.6</Version></req>";

 

 

If I dont want to send hardcoded parameters and want to send user defined parameters like I took a variable param as String ( QString param )   to store something and want to post this . Then how should I do this in above code? 

 

 

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

Re: Working with HTTP

This can't work.
If server need POST request with post params then you need send:
Json or 'classic' params. I don't know what 'your' server needs.

 

You need send this:

QByteArray postParams;
postParams += "IMEI=blabla";
postParams += "&";
.............

 or try to send JSON. JSON you can create like @zmey wrote

QVariantMap post;
post.insert("IMEI", "140000000000000");
post.insert("Device", "devic model");
post.insert("Provider", "provide name");
post.insert("NType", "GSM/CDMA");
post.insert("OS", "device OS");

// after that you need to serialize it
// you can use JsonDataAccess

JsonDataAccess json;
QByteArray postArray;
json.saveToBuffer(post, &postArray);

manager.post(request, postArray);

 



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.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

How to post parameters in HTTP

Hello friends , 

 

 

 I need to post some parameters with request to my url .  I have following request parameters ---

 

postParameters ="<req><IMEI>A140990898912</IMEI><OS>2.3.3</OS><Provider>cricKet</Provider><NType>CDMA</NType><Num>ODQzOTI2NDM4Nw==</Num><Device>Android%20unknown%20ADR3010</Device><Version>1.1.9.6</Version></req>";

 But as done here I dont want to post hardcoded parameters.

  for e.g  If I take imei in String like this 

QString deviceImei = info.imei();

 and want to send deviceImei variable to my url and all other parameters likewise this.  then how would I do this ?

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

Re: How to post parameters in HTTP

[ Edited ]
QUrl url("http://blabla");
url.addQueryItem("IMEI", info.imei().toUtf8());
url.addQueryItem("param2", "value2");
url.addQueryItem("param3", "value3");
url.addQueryItem("param4", "value4");

 

Look here GET/POST example

http://supportforums.blackberry.com/t5/Native-Development/Working-with-server/m-p/2652775/highlight/...

 

BTW: Are you have two accounts dhiraj_n, or? If you've why you make a new post with same question?



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.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: How to post parameters in HTTP

But this works fine whatever I have mentioned in earlier post (posting parameters in single line) . And now I just want to post parameters as I said instead of hardcoded parameters

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

Re: How to post parameters in HTTP

[ Edited ]

Hm, i don't know what you really want.
You can send own paramaters. As i wrote above

 

URL query items:

QUrl url("http://mypage.com");
url.addQueryItem("param1", "value1");
url.addQueryItem("param2", "value2");
..............

// result is:
// "http://mypage.com?param1=value1&param2=value2" 

 or POST params

QUrl url("http://mypage.com");

QUrl parameters;
parameters.addQueryItem("param1", "value1");
parameters.addQueryItem("param2", "value2");
.............

manager.post(request, parameters.encodedQuery());

 or JSON

QVariantMap post;
post.insert("IMEI", "140000000000000");
post.insert("Device", "devic model");
post.insert("Provider", "provide name");
post.insert("NType", "GSM/CDMA");
post.insert("OS", "device OS");

// after that you need to serialize it
// you can use JsonDataAccess

JsonDataAccess json;
QByteArray postArray;
json.saveToBuffer(post, &postArray);

manager.post(request, postArray);

That's it

Choose what you want :smileywink:



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.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: How to post parameters in HTTP

[ Edited ]

You are not getting my point.   I said I dont want to post parameters as hardcoded and you are telling me to post hardcoded parameters . Let me explain this thing ..

 

Suppose I want to post Message  to server then first I would get it by this and will store it in QString .

 

QString sms = message.body(MessageBody::PlainText).plainText();

 Then I would post this sms variable to my url . And If we do this as per your suggestion

 

here param1 means Message tag in request i.e. 

<req><Message>  </Message></req>

 

URL query: 

QUrl url("http://mypage.com");
url.addQueryItem("param1", "sms");

 Post params :

 

QUrl url("http://mypage.com");

QUrl parameters;
parameters.addQueryItem("param1", "sms");

 JSON:

QVariantMap post;
post.insert("Message", "sms");

 

 

then it will post "sms" as parameter and not the actual message which get received . I want to post the actual message .

 

 

 

 

 

Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: How to post parameters in HTTP

Maybe I'm misunderstanding something, but why can't you pass a variable to insert() ?

QString sms = ".....";

post.insert("Message", sms);

 

Last post in the original thread has an example of creating a string from JSON object:

http://supportforums.blackberry.com/t5/Native-Development/Working-with-HTTP/td-p/2665835

 

Please don't create multiple threads on the same topic. I'll ask moderator to merge them.

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: How to post parameters in HTTP

Hello Zmey,

            I apologize for it but my issues were different in these both cases thats why I had posted .

Please use plain text.