Skip to main content
rkaya
Associate
Nov 27, 2018 5:45 PM UTC
Question

HTTP POST & GET, under socket connection

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.

    This topic has been closed for replies.

    5 replies

    Elio Cometti
    Visitor II
    Nov 27, 2018 6:00 PM UTC

    ​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
    rkayaAuthor
    Associate
    Nov 27, 2018 6:16 PM UTC

    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?

    rkaya
    rkayaAuthor
    Associate
    Nov 27, 2018 6:06 PM UTC

    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
    Visitor II
    Nov 28, 2018 11:35 AM UTC

    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

    rkaya
    rkayaAuthor
    Associate
    Nov 28, 2018 3:23 PM UTC

    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.