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
Developer
Posts: 74
Registered: ‎03-04-2012
My Device: developer
My Carrier: developer

Network connection and posting data on sever

Hey hi All

 

I have just started working on BB 10 Cascades and I am try to post data on server but don't how to make network connection and append request pram with URL

 

please help

 

Regards

 

Deepak 

 

 

Deepak Charya
Developer
Posts: 411
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Network connection and posting data on sever

Take a look at the code in this posting.

 

http://supportforums.blackberry.com/t5/Cascades-Development/Activity-Indicator-Signals-and-C/td-p/20...

 

You could change

 

const char* const HTTPRead::m_dataAddress = "http://www.schofieldcomputer.com/StudyWar.mp3";

 to

 

const char* const DataModel::m_dataAddress = "http://www.mysite.com/myscript.php";

 

and then pass a query string that contains the data that you want to pass.

 

	QString encodedQuery = QUrl(m_urlQuery).toEncoded();

	QString path = m_dataAddress + encodedQuery;

 This should get you started.

 

 

 

 

Developer
Posts: 74
Registered: ‎03-04-2012
My Device: developer
My Carrier: developer

Re: Network connection and posting data on sever

Hey hi 

 

Thanks for Reply but I don't understand here how to add request param with the URL so that I can call Http post method as in like we use to in BB java development

 

Regards

 

Deepak

Deepak Charya
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: Network connection and posting data on sever

first important part: THINK ASYNC !

use SLOTS and SIGNALS

you need a QNetworkAccessManager

mNetworkAccessManager = new QNetworkAccessManager(this);

	bool connectOK = connect(mNetworkAccessManager,
			SIGNAL(finished(QNetworkReply*)), this,
			SLOT(requestFinished(QNetworkReply*)));

 you do your request and every time the work is done you'll get the reply into your slot.

to create your request some snippets:

QNetworkRequest request = QNetworkRequest();
// GET
request.setUrl(QUrl(mBaseUrl+......));
...
mNetworkAccessManager->get(request);
------------------
// or a POST with some JSON data
QByteArray mRequestJson =
	"{\"username\":\""
	+ mUser.toUtf8()
	+ "\",\"password\":\""
	+ mPassword.toUtf8()
	+"\"}";
...
postDataSize = QByteArray::number(mRequestJson.size());			request.setHeader(QNetworkRequest::ContentLengthHeader, postDataSize);
...
request.setRawHeader("Accept", "application/json");
...			request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
...
request.setRawHeader("charset", "utf-8");
...
mNetworkAccessManager->post(request, mRequestJson);

 if finished you process the reply

void YourApp::requestFinished(QNetworkReply* reply) {
    if (reply->error() == QNetworkReply::NoError) {
        // process the reply
    } else your error stuff
}

 hope this gives you some hints

if all these Q... Classes are new for you: take a look at great documentation from Cascades.

ekke

if my post helps you: accept as solution and/or like it

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Highlighted
Developer
Posts: 74
Registered: ‎03-04-2012
My Device: developer
My Carrier: developer

Re: Network connection and posting data on sever

hi ekke,

Thanks for reply, sorry got stuck somewhere else so reading your post today...e
Here i am using rest base services as in Blackberry java development we make use of URLEncodedpost to post data with
URL. here i dont found any such thing. Following your suggestion i tried doing the same instead of json i tried adding my parameters in reqParam here like this

QByteArray reqParam = "username=name&password=1234&auth=1";

also as

QByteArray reqParam = "username=name";
reqParam.append("password=1234");
reqParam.append("auth=1");

but not getting success

Regards
Deepak
Deepak Charya