简体   繁体   中英

Sending a HTTP Request Post in Json

I 'm having what is follow:

void MainWindow::uploadText(){
QUrl parameters;
parameters.addQueryItem("OrgName","MM");
parameters.addQueryItem("Type","Article");
parameters.addQueryItem("ExpiraryDate","12/2/2012");

QNetworkRequest request(QUrl("http://xxxxxxxxxx"));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

QNetworkAccessManager *manager= new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(sendReportToServerReply(QNetworkReply*)));
QNetworkReply *reply = manager->post(request,parameters.encodedQuery()); 

}

At which level I have to deal with the Json parse and serialization format in my code?

If you're using Qt5 then there's JSON serialisation libraries already built in, if you're not you'll need an external one such as: qt-json . You do the serialisation and then add it into the header, however you may need to manually build the header instead of using addQueryItem .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM