HTTP Content-Type

Hi All,

I am new to quectel and i bought quectel EC20 EVB.
In my application i am using HTTP and i need to send data in JSON format.

But i cannot find any way to set Content-Type as application/json.

If you know how to set application/json please guide me.

In document only four method is available to set content type.

If content-type = application/json is possible then please explain that steps.

Thanks,
Hardik

AT+QHTTPCFG
+QHTTPCFG: “requestheader”,<request_header>
+QHTTPCFG: “responseheader”,<response_header>

Thanks for reply WizIO,

AT+QHTTPCFG:“requestheader”,1

After that what is step and where i have to give application/json Content-type in which format.


just google :slight_smile:

Thank you WizIO,

Finally i set content-type as application/json using below method…

TEST URL: http://iot.hardikpokar.in/fold/devicereg
TEST PAYLOAD: {“id”:123,“USER”:1}

1)AT+QICSGP=1
2)AT+QIACT=1
3)AT+QIACT?
4)AT+QHTTPCFG=“contextid”,1
5)AT+QHTTPCFG=“requestheader”,1

6)AT+QHTTPURL=41,80
Connect
http://iot.hardikpokar.in/fold/devicereg
OK

7)AT+QHTTPPOST=135,80,80
Connect
POST /fold/devicereg HTTP/1.1
Host: iot.hardikpokar.in
Content-Type: application/json
Accept: /
Content-Length: 19
//Don’t miss this line
{“id”:123,“USER”:1}

OK
8)AT+QHTTPREAD=80

status:success

Thank you,
Hardik

:slight_smile: you welcome …

HI
I AM USING AN EC21-E MODULE
I AM TRYING TO POST A JSON DATA

MY CODE IS ATTACHED
AT+QHTTPCFG=“contextid”,1

OK
AT+QHTTPCFG=“requestheader”,1

OK
AT+QIACT=1

OK
AT+QIACT?

+QIACT: 1,1,1,“25.106.158.28”

OK
AT+QICSGP=1,1,“JIONET”,"" ,"" ,1

OK
AT+QHTTPURL=73,80

CONNECT

OK
AT+QHTTPPOST=171,80,80

CONNECT

OK
POST /fold/devicereg HTTP/1.1
Host: https://ntiiippretail.com
Content-Type: application/json
Accept: /
Content-Length: 58
{ “Temperature” : “27.45” ,“MacId” : “4c:22:55:45:ff:77”}

+QHTTPPOST: 0,400,339

AT+QHTTPREAD=80

AND I AM GETTING A RESPONSE LIKE THIS

Bad Request

Bad Request - Invalid Header


HTTP Error 400. The request has an invalid header name.

I think you missed one line between header and body content.

Best Regards,

Hi ismail_mirsa,

send Payload ::

https://ntiiippretail.com/fold/devicereg
Hope your Full URL is like this only .if any change in Path please replace that path in Payload.

And after Content-Type you need to give one line Extra between you header and Body. Content-Type:application/json\r\n**\r\n**

Regards,
Hardik

thanks willie yao…it helped

thanks hardik…
you were right i tried with that extra line which i missed and i was able to rectify invalid header error.
but an error indicating invalid host name occured afterwards .
so i changed the host name starting from https to www
and it worked .
status : true

Hi Bhavish_yadav:
You can refer to the steps Hardik_Pokar wrote:

1 Like

THANKS FOR THE HELP.
I have successfully posted the JSON data. Now the next challenge is how to parse the JSON data.
after calling AT+QHTTPGET=80 AND Then AT+QHTTPREAD=80;
PLEASE help

Hi Bhavish_yadav:
You are welcome. GET request cannot carry content.It can only request content from the server.
After you execute get successfully, you can directly read the content requested from the server through AT+QHTTPREAD=80.

Hello, I’m currently working with EC200U for HTTP GET and POST requests. I’m unsure why it’s displaying bad requests when using AT commands, but I’m able to successfully work with it using Postman software.

[2024-03-21 10:00:26:342_S:] AT+QIDEACT=1
[2024-03-21 10:00:26:395_R:] AT+QIDEACT=1
[2024-03-21 10:00:26:489_R:] OK
[2024-03-21 10:00:27:361_S:] AT+QICSGP=1,1,“www”,“”,“”,0
[2024-03-21 10:00:27:419_R:] AT+QICSGP=1,1,“www”,“”,“”,0
[2024-03-21 10:00:27:419_R:] OK
[2024-03-21 10:00:28:370_S:] AT+QIACT?
[2024-03-21 10:00:28:428_R:] AT+QIACT?
[2024-03-21 10:00:28:428_R:] OK
[2024-03-21 10:00:29:396_S:] AT+QIACT=1
[2024-03-21 10:00:29:455_R:] AT+QIACT=1
[2024-03-21 10:00:29:612_R:] OK
[2024-03-21 10:00:30:423_S:] AT+QIACT?
[2024-03-21 10:00:30:483_R:] AT+QIACT?
[2024-03-21 10:00:30:483_R:] +QIACT: 1,1,1,“100.99.241.117”

[2024-03-21 10:00:30:483_R:] OK
[2024-03-21 10:00:31:434_S:] AT+QHTTPCFG=“contextid”,1
[2024-03-21 10:00:31:492_R:] AT+QHTTPCFG=“contextid”,1
[2024-03-21 10:00:31:492_R:] OK
[2024-03-21 10:00:32:459_S:] AT+QHTTPCFG=“requestheader”,1
[2024-03-21 10:00:32:518_R:] AT+QHTTPCFG=“requestheader”,1
[2024-03-21 10:00:32:518_R:] OK
[2024-03-21 10:00:33:480_S:] AT+QHTTPURL=33,80
[2024-03-21 10:00:33:539_R:] AT+QHTTPURL=33,80
[2024-03-21 10:00:33:539_R:] CONNECT

[2024-03-21 10:00:33:540_R:] DSR:1 CTS:1 RI:0 (DCD:1)
[2024-03-21 10:00:34:505_S:] http://emprostar.com:423/api/login

[2024-03-21 10:00:34:565_R:] OK
[2024-03-21 10:00:35:533_S:] AT+QHTTPPOST=147,80,80
[2024-03-21 10:00:35:593_R:] AT+QHTTPPOST=147,80,80
[2024-03-21 10:00:35:840_R:] CONNECT
[2024-03-21 10:00:36:545_S:] POST /api/login HTTP/1.1
[2024-03-21 10:00:37:558_S:] Host: emprostar.com:423
[2024-03-21 10:00:38:582_S:] Content-Type: application/json
[2024-03-21 10:00:39:607_S:] Accept: /
[2024-03-21 10:00:40:627_S:] Content-Length: 52
[2024-03-21 10:00:41:635_S:] {“Username”: “shubhangi”,“Password”: “shubhangi123”}

[2024-03-21 10:00:41:693_R:] OK

[2024-03-21 10:00:42:004_R:] +QHTTPPOST: 0,400,339
[2024-03-21 10:00:42:660_S:] AT+QHTTPREAD=80
[2024-03-21 10:00:42:720_R:] AT+QHTTPREAD=80
[2024-03-21 10:00:42:720_R:] CONNECT
[2024-03-21 10:00:42:720_R:]
[2024-03-21 10:00:42:720_R:] Bad Request
[2024-03-21 10:00:42:720_R:]
[2024-03-21 10:00:42:720_R:]

Bad Request - Invalid Header


[2024-03-21 10:00:42:720_R:]

HTTP Error 400. The request has an invalid header name.


[2024-03-21 10:00:42:720_R:]

[2024-03-21 10:00:42:720_R:] OK

[2024-03-21 10:00:42:844_R:] +QHTTPREAD: 0