UC20 Post Customize HTTP Request Header

Hi i buy a uc20. i post some data to URL. everything is fine when “requestheader” is 0 and send data with default format. but i want send data in json format. i search all the forums but not find anything useful.
my code is below:

printf(“AT+QIDEACT=1\r”);
printf(“AT+QHTTPCFG=“contextid”,1\r”);
printf(“AT+QICSGP=1,1,“mtnIrancell”,”","",1\r");
printf(“AT+QIACT=1\r”);
printf(“AT+QHTTPCFG=“requestheader”,1\r”);
printf(“AT+QHTTPCFG=“responseheader”,1\r”);
printf(“AT+QHTTPURL=36,80\r”);
printf(“http://javaddehghan.ir/post-json.php”);
printf(“AT+QHTTPPOST=%d,80,80\r”, 215);
printf(“POST/post-json.php HTTP/1.1\r\n”);
printf(“HOST: http://javaddehghan.ir\r\n”);
printf(“Content-Type: application/x-www-form-urlencoded\r\n”);
printf(“Accept: /\r\n”);
printf(“User-Agent: QUECTEL_MODULE\r\n”);
printf(“Connection: Keep-Alive\r\n”);
printf(“Content-Length: 20\r\n”);
printf("\r\n");
printf("{“name”:javad"id":5}");
printf(“AT+QHTTPREAD=80\r”);

error code is 400 and description is “Bad Request”.
i test the url with postman software and it was ok.

Hi javad
Thanks for your query.
please send the responses of the all AT commands you have used.
please look at the below AT command logs. I think it will solve your issue. As it is posting and reading data successfully from your server.
[2020-05-12_11:01:14:034]
[2020-05-12_11:01:14:034]+CPIN: READY

[2020-05-12_11:01:14:034]+QUSIM: 1
[2020-05-12_11:01:14:120]ATE1

[2020-05-12_11:01:14:120]OK
[2020-05-12_11:01:16:026]AT+CSQ

[2020-05-12_11:01:16:028]+CSQ: 99,99

[2020-05-12_11:01:16:028]OK
[2020-05-12_11:01:17:740]AT+CSQ

[2020-05-12_11:01:17:740]+CSQ: 99,99

[2020-05-12_11:01:17:740]OK
[2020-05-12_11:01:20:673]AT+CSQ

[2020-05-12_11:01:20:673]+CSQ: 99,99

[2020-05-12_11:01:20:673]OK
[2020-05-12_11:01:20:797]
[2020-05-12_11:01:20:797]+QIND: SMS DONE
[2020-05-12_11:01:22:475]AT+CSQ

[2020-05-12_11:01:22:475]+CSQ: 31,5

[2020-05-12_11:01:22:475]OK
[2020-05-12_11:01:25:422]AT+CGREG?

[2020-05-12_11:01:25:422]+CGREG: 0,1

[2020-05-12_11:01:25:422]OK
[2020-05-12_11:01:29:990]AT+QHTTPCFG=“contextid”,1

[2020-05-12_11:01:29:990]OK
[2020-05-12_11:01:31:202]AT+QICSGP=1,1,“airtelgprs.com”,"","",1

[2020-05-12_11:01:31:202]OK
[2020-05-12_11:01:33:733]AT+QIACT=1

[2020-05-12_11:01:36:204]OK
[2020-05-12_11:01:38:982]AT+QIACT?

[2020-05-12_11:01:38:982]+QIACT: 1,1,1,“100.76.19.61”

[2020-05-12_11:01:38:982]OK
[2020-05-12_11:01:42:020]AT+QHTTPCFG=“requestheader”,0

[2020-05-12_11:01:42:023]OK
[2020-05-12_11:01:44:155]AT+QHTTPCFG=“responseheader”,1

[2020-05-12_11:01:44:155]OK
[2020-05-12_11:01:47:331]
[2020-05-12_11:01:47:331]+QIND: PB DONE
[2020-05-12_11:01:51:375]AT+QHTTPURL=36,80

[2020-05-12_11:01:51:375]CONNECT
[2020-05-12_11:01:52:048]
[2020-05-12_11:01:52:048]OK
[2020-05-12_11:01:58:061]AT+QHTTPPOST=20,80,80

[2020-05-12_11:01:59:510]CONNECT
[2020-05-12_11:02:00:471]
[2020-05-12_11:02:00:471]OK
[2020-05-12_11:02:01:255]
[2020-05-12_11:02:01:255]+QHTTPPOST: 0,200,9
[2020-05-12_11:02:03:657]AT+QHTTPREAD=80

[2020-05-12_11:02:03:657]CONNECT
[2020-05-12_11:02:03:657]HTTP/1.1 200 OK
[2020-05-12_11:02:03:657]Content-Type: text/html; charset=UTF-8
[2020-05-12_11:02:03:657]Cache-Control: public, max-age=0
[2020-05-12_11:02:03:657]Expires: Tue, 12 May 2020 05:32:00 GMT
[2020-05-12_11:02:03:657]Content-Length: 9
[2020-05-12_11:02:03:657]Date: Tue, 12 May 2020 05:32:00 GMT
[2020-05-12_11:02:03:657]Connection: Keep-Alive

[2020-05-12_11:02:03:657]Hey
[2020-05-12_11:02:03:657]Hel2

[2020-05-12_11:02:03:657]OK
[2020-05-12_11:02:03:689]
[2020-05-12_11:02:03:689]+QHTTPREAD: 0

Also you can use the AT+QHTTPCFG=“contenttype”,[0-3] command
where 0-3 as follows image

2 Likes

Hi Rahul
thanks for your reply. i am so glad that you get response from it. i was hopeless from answer and try to debug again. i get success two days ago. as you say above command are correct. the problem was in at command (“ATE1”). when “ATE1” module echo my commands i send to it and cause mistake. i change “ATE1” to “ATE0” and that was OK.
i was mistake two of above lines that must change:

printf(“Content-Length: 23\r\n”);
printf("{“name”:“javad”,“id”:5}");