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

New Developer
Posts: 19
Registered: ‎11-13-2013
My Device: Q10
My Carrier: Verizon
Accepted Solution

Help with HTTP Post JSON Request

Still fairly new to QT so I'm trying to send a http post request with some json, I'm pulling the json from a file and that seems to be working fine but I keep getting a http 500 error. I just want to ensure my code is correct before contacting the company who webservice I'm using here is my code:



 JsonDataAccess jda;
    QVariant list = jda.load(QDir::currentPath() +"/app/native/assets/jsonData/myjson.json");


    QUrl webServiceUrl("https://thewebserviceurl/");
    QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager(this);
    QNetworkRequest request (webServiceUrl);

    request.setRawHeader("Content-Type", "application/json");
    request.setRawHeader("Content-Length", QByteArray::number(list.toByteArray().size()));

    QNetworkReply *reply = networkAccessManager->post(request, list.toByteArray());


I have a feeling I'm passing in the json data into the post method incorrect. Any assistance is appreicated

Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Help with HTTP Post JSON Request

[ Edited ]


You are sending an empty string to server because list.toByteArray() returning empty string.


You need save list to QByteArray;


QByteArray result;
jda.saveToBuffer(list, &result);

// and then

QNetworkReply *reply = networkAccessManager->post(request, result);



Just load the json file with QFile

QFile file(YOUR_JSON);
if (!file.open(QIODevice::ReadOnly)){
    qDebug() << Q_FUNC_INFO << file.errorString();
QByteArray result = file.readAll();

QNetworkReply *reply = networkAccessManager->post(request, result);

 Hoe it helps Smiley Wink


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
New Developer
Posts: 19
Registered: ‎11-13-2013
My Device: Q10
My Carrier: Verizon

Re: Help with HTTP Post JSON Request

That did the trick thanks!