samples: net: http_get: fixes for fetching google.com
Minor fixes to ensure GET google.com is successful. Signed-off-by: Ryan Erickson <ryan.erickson@ezurio.com>
This commit is contained in:
parent
522718d7fd
commit
490e67528a
1 changed files with 8 additions and 8 deletions
|
|
@ -30,7 +30,7 @@
|
|||
#endif
|
||||
|
||||
/* HTTP server to connect to */
|
||||
#define HTTP_HOST "google.com"
|
||||
#define HTTP_HOST "www.google.com"
|
||||
/* Port to connect to, as string */
|
||||
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
|
||||
#define HTTP_PORT "443"
|
||||
|
|
@ -40,11 +40,10 @@
|
|||
/* HTTP path to request */
|
||||
#define HTTP_PATH "/"
|
||||
|
||||
|
||||
#define SSTRLEN(s) (sizeof(s) - 1)
|
||||
#define CHECK(r) { if (r == -1) { printf("Error: " #r "\n"); exit(1); } }
|
||||
#define CHECK(r) { if (r < 0) { printf("Error: %d\n", r); exit(1); } }
|
||||
|
||||
#define REQUEST "GET " HTTP_PATH " HTTP/1.0\r\nHost: " HTTP_HOST "\r\n\r\n"
|
||||
#define REQUEST "GET " HTTP_PATH " HTTP/1.1\r\nHost: " HTTP_HOST "\r\n\r\n"
|
||||
|
||||
static char response[1024];
|
||||
|
||||
|
|
@ -52,9 +51,8 @@ void dump_addrinfo(const struct addrinfo *ai)
|
|||
{
|
||||
printf("addrinfo @%p: ai_family=%d, ai_socktype=%d, ai_protocol=%d, "
|
||||
"sa_family=%d, sin_port=%x\n",
|
||||
ai, ai->ai_family, ai->ai_socktype, ai->ai_protocol,
|
||||
ai->ai_addr->sa_family,
|
||||
((struct sockaddr_in *)ai->ai_addr)->sin_port);
|
||||
ai, ai->ai_family, ai->ai_socktype, ai->ai_protocol, ai->ai_addr->sa_family,
|
||||
ntohs(((struct sockaddr_in *)ai->ai_addr)->sin_port));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
|
@ -110,7 +108,9 @@ int main(void)
|
|||
HTTP_HOST, sizeof(HTTP_HOST)))
|
||||
#endif
|
||||
|
||||
printf("Connecting to server...\n");
|
||||
CHECK(connect(sock, res->ai_addr, res->ai_addrlen));
|
||||
printf("Connected!\r\nSending request...\n");
|
||||
CHECK(send(sock, REQUEST, SSTRLEN(REQUEST), 0));
|
||||
|
||||
printf("Response:\n\n");
|
||||
|
|
@ -131,7 +131,7 @@ int main(void)
|
|||
printf("%s", response);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("\nClose socket\n");
|
||||
|
||||
(void)close(sock);
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue