mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Fix http_request example
1) WEB_PATH should path relative to document root of web server. 2) HTTP request should contain "Host" header of format "host:port". 3) Port number in the example should be configurable.
This commit is contained in:
parent
c27fd32fbe
commit
e255c48de7
@ -24,13 +24,13 @@
|
|||||||
|
|
||||||
/* Constants that aren't configurable in menuconfig */
|
/* Constants that aren't configurable in menuconfig */
|
||||||
#define WEB_SERVER "example.com"
|
#define WEB_SERVER "example.com"
|
||||||
#define WEB_PORT 80
|
#define WEB_PORT "80"
|
||||||
#define WEB_URL "http://example.com/"
|
#define WEB_PATH "/"
|
||||||
|
|
||||||
static const char *TAG = "example";
|
static const char *TAG = "example";
|
||||||
|
|
||||||
static const char *REQUEST = "GET " WEB_URL " HTTP/1.0\r\n"
|
static const char *REQUEST = "GET " WEB_PATH " HTTP/1.0\r\n"
|
||||||
"Host: "WEB_SERVER"\r\n"
|
"Host: "WEB_SERVER":"WEB_PORT"\r\n"
|
||||||
"User-Agent: esp-idf/1.0 esp32\r\n"
|
"User-Agent: esp-idf/1.0 esp32\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ static void http_get_task(void *pvParameters)
|
|||||||
char recv_buf[64];
|
char recv_buf[64];
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
int err = getaddrinfo(WEB_SERVER, "80", &hints, &res);
|
int err = getaddrinfo(WEB_SERVER, WEB_PORT, &hints, &res);
|
||||||
|
|
||||||
if(err != 0 || res == NULL) {
|
if(err != 0 || res == NULL) {
|
||||||
ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res);
|
ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res);
|
||||||
|
Loading…
Reference in New Issue
Block a user