简体   繁体   中英

QNetworkAccessManager - How to send MultiPart “PATCH” request

This question complements QNetworkAccessManager - How to send “PATCH” request .

QNetworkAccessManager has no method

sendCustomRequest(const QNetworkRequest & request, const QByteArray & verb, QHttpMultiPart * multiPart)

I'm stuck with Qt 4.8-bb10. How should I proceed?

I think you can build the multipart request yourself by putting the extra parts in the data, like below.

Sorry but I was unable to test so this is just the rough idea.

QUrl url("http://data.mybusiness.com/patches");
QNetworkRequest request(url);
QString boundary("------------------------------------asdfyiuqwer762345");
request.setRawHeader("Content-Type", QByteArray("multipart/form-data; boundary=").append(boundary));

QByteArray data;
data.append("--" + boundary + "\r\n");
data.append("Content-Disposition: form-data; name=\"City\"\r\n");
data.append("\r\n");
data.append("Paris\r\n");
data.append("--" + boundary + "\r\n");

data.append("Content-Disposition: form-data; name=\"Country\"\r\n");
data.append("\r\n");
data.append("Canada\r\n");
data.append("--" + boundary + "--\r\n");
/* Final boundary has extra -- at end */

QBuffer * pBuffer = new QBuffer(pNetworkAccessManager);
pBuffer->setData(data);

QNetworkReply * pReply = pNetworkAccessManager->sendCustomRequest(request, "PATCH", pBuffer);

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