如何使用QNetworkAccessManager将数据发布到URL
问题描述:
我有一个Web服务,我需要发布一些数据才能使用Qt. 我认为在发布到Web服务时可以使用QByteArray.
I have a webservice that I need to POST some data to using Qt. I figured that I can use a QByteArray when POSTing to the web service.
我的问题是,如何格式化该数组以便在另一端正确解析?
My question is, how can I format this array in order to be parsed correctly at the other end?
这是我到目前为止的代码:
This is the code I have so far:
// Setup the webservice url
QUrl serviceUrl = QUrl("http://myserver/myservice.asmx");
QByteArray postData;
/*
Setup the post data somehow
I want to transmit:
param1=string,
param2=string
*/
// Call the webservice
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*)));
networkManager->post(QNetworkRequest(serviceUrl), postData);
谢谢!
答
我使用过:
QByteArray postData;
postData.append("param1=string&");
postData.append("param2=string");
所以&而不是每个参数后的换行符.
So & instead of newline after each parameter.