0

QTCPSocket data contains HTTP header and JSON. How to parse only JSON from this?

POST / HTTP/1.1\r\nContent-Type: application/json\r\nContent-Length: 208\r\nConnection: Keep-Alive\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: ru-RU,en,*\r\nUser-Agent: Mozilla/5.0\r\nHost: localhost:5714\r\n\r\n
{\n\"profile\":{\n\"name\":\"ZH\",\n\"id\": 36359\n }}\n
Kesantielu Dasefern
  • 266
  • 1
  • 3
  • 12
  • If you deal with HTTP you should probably use `QNetworkAccessManager` instead of `QTcpSocket`. JSON parsing can be done using `QJsonDocument::fromJson` function. – Pavel Strakhov Jun 29 '16 at 13:02
  • Can I use `QNetworkAccessManager` on server side for processing requests from client? – Kesantielu Dasefern Jun 29 '16 at 13:11
  • Have a look at http://doc.qt.io/qt-5/qjsondocument.html - You will have to seperate the json from the header by yourself. – Felix Jun 29 '16 at 14:48

0 Answers0