How to send a POST method


#1

I have a site
in it by POST, must complete 2 fields
“Meas_Point” and “Date”

I do:

AT+WIPCREATE=5,1,“http://mysite.ru
OK
+WIPREADY: 5, 1

at+WIPFILE=5,1,4,“http://mysite.ru
CONNECT

/***** here i send
Meas_Point=5&Date=2011-03-29 08:12:47
/*****
+++
OK

website message does not come
what am I doing wrong?


#2

Hi

My application performs an HTTP post with the following WIPSoft AT commands:

// setup
AT+WIPCFG=1
AT+WIPBR=1,6
AT+WIPBR=2,6,11,"INTERNET"
AT+WIPBR=4,6,0

// create a client connection to the server. note the port number is 80 for http
AT+WIPCREATE=2,1,"xxx.xxx.xxx.xxx",80

// post the data
AT+WIPDATA=2,1,2
GET http://xxx.xxx.xxx.xxx/page_name.aspx?Data=data_formatted_as_a_string

// when the post is done, leave data mode and close the socket
+++AT+WIPCLOSE=2,1

Sorry, but I cannot include the responses to the commands above. (That system has gone live in the mean time, and I might get executed without trail if I start posting test data to it)

Hope this helps


#3

No it doesn’t - it performs an HTTP GET :exclamation:


#4

My bad.

The app uploads data to a server using HTTP GET. I was rather confused when the suppliers gave my this solution to upload my data, but it seemed to do the trick. The problem with this method is that I have to leave Data Mode after each GET; this becomes very time consuming and is not an option when you have dozens of records to upload.


#5

To send HTTP POST request, one should use socket mode TCP Client “2” instead of HTTP Client “5”.
You have to play with the HTTP POST header, e.g.

POST /post.php HTTP/1.1
Host: yourdomain.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 16

id=123&value=456

Instead, for HTTP GET, I think socket mode HTTP Client “5” is possible with better efficiency, you just concat the parameter in the request URL.

L


#6

[SOLUTION] Forgive me for reviving such an old thread, but I have struggled with this for several hours now and couldn’t find any decent references for doing an HTTP POST without embedding the POST data in the URL.

Here is what I believe to be a better approach. There is no such example in any official documentation I could find, but it seems to work. I added the solution here for future reference, as this is the first relevant page I found during my own search.

  1. Start IP Stack
AT+WIPCFG=1
OK
  1. Open GPRS bearer
AT+WIPBR=1,6
OK
  1. Set APN (replace “internet” with your APN)
AT+WIPBR=2,6,11,"internet"
OK
  1. Start GPRS bearer
AT+WIPBR=4,6,0
OK
  1. Connect TCP socket to remote server on port 80 in HTTP mode (substitute your URL, but you can use httpbin.org for testing)
AT+WIPCREATE=5,1,"httpbin.org",80
OK

+WIPREADY 5, 1
  1. Do HTTP POST (adjust the content type, content length and other header data to suit your needs)
AT+WIPFILE=5,1,4,"http://httpbin.org/post","","","Accept","*/*","Accept-Encoding","deflate","Content-Type","application/json","Content-Length","9"
OK
CONNECT

(NB: Now the modem is in data mode and does not echo bytes sent over UART)

It works![ETX]

(NB: [ETX] is the Unicode U+0003 character)

{
   "url": "http://httpbin.org/post",
                                      "json": null,
                                                     "data": "It works!",
                                                                           "form": {},
                                                                                        "origin": "10.xxx.xx.xxx",
             "headers": {
                             "Content-Type": "application/json",
                                                                    "Accept": "*/*",
                                                                                        "Accept-Encoding": "deflate",
                  "Connection": "close",
                                            "Content-Length": "9",
                                                                      "Host": "httpbin.org",
                                                                                                "Transfer-Encoding": "chunked"
                         },
                             "files": {},
                                           "args": {}
                                                     }
+WIPFILE: 5,1,4,200,"OK"

OK
  1. Close TCP socket
AT+WIPCLOSE=5,1