HTTP Requests - Example
Posted: Thu Apr 06, 2017 8:22 pm
I'm working from the HTTP_request_example, and it's not working exactly as I expected it to. Specifically, it's not printing the the HTTP response message to standard IO.
I'm testing via http://httpbin.org/get, and using both:
and Postman to send:
and in both cases I get the expected response:
However, when I configure the ESP-IDF HTTP Request example to match:
I also added an innocuous print statement to confirm the HTTP request that I think I'm sending is actually the one I'm sending with:
...which is inserted right before the request is written to the socket...
I get the following (abbreviated) output:
At this point it just waits. But i'm expecting it to print the response message based on this snippet:
So...where could I have gone wrong on this?
I'm testing via http://httpbin.org/get, and using both:
Code: Select all
$ curl http://httpbin.org/get
and Postman to send:
Code: Select all
GET /get HTTP/1.1
Host: httpbin.org
User-Agent: esp-idf/1.0 esp32
Code: Select all
{
"args": {},
"headers": {
"Accept": "*/*",
"Connection": "close",
"Host": "httpbin.org",
"User-Agent": "curl/7.51.0"
},
"origin": "73.0.241.158",
"url": "http://httpbin.org/get"
}
Code: Select all
/* Constants that aren't configurable in menuconfig */
#define WEB_SERVER "httpbin.org"
#define WEB_PORT 80
#define WEB_URL "/get"
Code: Select all
printf("%s", REQUEST);
I get the following (abbreviated) output:
Code: Select all
(2210) example: Connected to AP
I (2380) example: DNS lookup succeeded. IP=184.72.248.171
I (2380) example: ... allocated socket
I (2430) example: ... connected
GET /get HTTP/1.1
Host: httpbin.org
User-Agent: esp-idf/1.0 esp32
I (2430) example: ... socket send success
I (11180) wifi: pm start, type:0
Code: Select all
/* Read HTTP response */
do {
bzero(recv_buf, sizeof(recv_buf));
r = read(s, recv_buf, sizeof(recv_buf)-1);
for(int i = 0; i < r; i++) {
putchar(recv_buf[i]);
}
} while(r > 0);