cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP POST & GET, under socket connection

rkaya
Associate II

I have configured One way authentication mode and able to connect to the server successfully.

After getting socket ID, I am using AT+SOCKW command to POST and GET.

e.g.

AT+SOCKW=00, 18<CR> (18 length is example)

POST /api/Frames HTTP/1.1<CR><LF>

DATA......

<CR><LF>

AT+SOCKW=00,18<CR>

GET /api/Contracts HTTP/1.1<CR><LF>

<CR><LF>

and in response always getting HTTP:400 Bad request error.

Please give a technical person contact number of ST employee, or please suggest solution on this.

5 REPLIES 5
Elio Cometti
Senior II

​Hello,

I think you are doing the right think but probably your request is incorrect.

I mean, some headers (like Host, Content-Length in POST request) may be missing. Some fields are mandatory, others may be required by the web server and leading to a Bad Request reply if they are not sent by client.

Regards,

Elio

rkaya
Associate II

Thanks for your feedback.

Could you please confirm, how to configure/send header contents ?

How to send it?

POST /api/Frames HTTP/1.1<CR><LF>

HOST:***.com

Content_length: xx

Data..............

<CR><LF>

is this correct way ?

Can i use "HTTPPOST=url,path,data,443<CR> "

to post data to https server?

Thanks for your feedback.

Could you please confirm, how to configure/send header contents ?

How to send it?

POST /api/Frames HTTP/1.1<CR><LF>

HOST:***.com

Content_length: xx

Data..............

<CR><LF>

is this correct way ?

Can i use "HTTPPOST=url,path,data,443<CR> "

to post data to https server?

Elio Cometti
Senior II

Hello,

your header seems correct (just need to add a <CR><LF> at end of every header lines).

I suppose you are using SPWF01 for this, AT+S.HTTPPOST does only perform http requests and does not support https (that are based on TLS) requests.

For a normative reference on HTTP 1.1, I kindly suggest to have a look to RFC2616 (and updates).

You may also exercise with others application: for example if you have a Linux machine then you might try the following to get a valuable header:

nc -l 12345 | xxd -g 1 &

wget --post-data "This is a test POST message" -q http://localhost:12345

You can also get this kind of info from developer tools of your browser.

Regards,

Elio

Hi Elio,

After HTTP POST, getting HTTP 500 Internal server error.

(\"Message\":\"An error has occured)

Could you please suggest on this?

I am able to test with POSTMAN application.