0

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?

Community
  • 1
  • 1
Bill_BsB
  • 314
  • 3
  • 14

1 Answers1

0

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);
mjk99
  • 1,290
  • 11
  • 18
  • Thanks mjk99! I used your technique to implement what I needed and it worked flawlessly! A little bit more cumbersome but still doable. – Bill_BsB Feb 29 '16 at 11:38
  • Great! I'm glad it was close enough you could figure it out. I usually have to fiddle with newlines to get it working. You can send any type of data of course, not just text. – mjk99 Feb 29 '16 at 16:39