Solved How should post data to API that has ContentTypeHeader:"text/plain; charset=utf-8" ?
-
This post is deleted! -
@SGaist am I get the correctly contentTypeheader With that link ?
-
And am I use contentTypeHeader correctly?
-
Did you check what the endpoint you are sending requests to requires ?
-
Can you show us an example of valid request to your API? Maybe using curl?
P.S.
Qt tutorials from https://www.bogotobogo.com should be avoided, they are of very low quality and sometimes encourage toxic patterns in code. -
@SGaist @VRonin I send post request with postman in google chrome
I set header Content-Type:"application/json"
in body section I choose raw
and data:"122,2019/02/21,10:54:31"
data is successfully posted to the API and I can see it on the URLI change my code :
QNetworkRequest request(QUrl("http://site.com/api/PtData/")); request.setRawHeader("Content-Type", "application/json"); QByteArray data("102,2018/02/16,19:17:23"); QNetworkAccessManager nam; QNetworkReply *reply = nam.post(request, data);
I do not get any errors, but when I check the URL, the data is not post(set)on it
-
Except that what you send is not valid JSON.
-
@SGaist but I post the same format data that I use in postman
POST /api/PatData/ HTTP/1.1 Host: site.com Content-Type: application/json Cache-Control: no-cache Postman-Token: c31beda7-12bf-d5b8-4945-88895d0727a0 "102,2019/02/21,23:31:21"
-
You should check the data sent using postman.
-
I checked the C code in postman the data format must be :
QByteArray data("\"185,2019/02/22,10:59:21\"");
Finally it's post successfuly :-/