QNetworkAccessManager - 如何发送多部分“PATCH”请求

QNetworkAccessManager - How to send MultiPart “PATCH” request

这个问题补充 .

QNetworkAccessManager 没有方法

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

我坚持使用 Qt 4.8-bb10。我该如何进行?

我认为您可以通过将额外的部分放入数据中来自己构建多部分请求,如下所示。

抱歉,我无法测试,所以这只是粗略的想法。

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);