This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sdk:httpget [2015/07/02 13:02] – created fachet | sdk:httpget [2015/07/02 14:15] (current) – fachet | ||
---|---|---|---|
Line 7: | Line 7: | ||
if (send(s, "GET / HTTP/ | if (send(s, "GET / HTTP/ | ||
if ((r = recv(s)) == NULL) exit(4); | if ((r = recv(s)) == NULL) exit(4); | ||
- | printf(" | + | printf(" |
+ | if (!strstr(r, " | ||
+ | i = substr(r, strstr(r, "IP Address: ") + 12, strlen(r)); | ||
+ | | ||
+ | } | ||
close(s); | close(s); | ||
+ | exit(0); | ||
</ | </ | ||
<code c Output> | <code c Output> | ||
- | |||
HTTP/1.1 200 OK | HTTP/1.1 200 OK | ||
Content-Type: | Content-Type: | ||
Line 23: | Line 27: | ||
< | < | ||
+ | IP Address: 89.12.4.18 | ||
+ | </ | ||
+ | | ||
+ | <code c httpget2.are> | ||
+ | To get from or post data to a web server you can easily use standard sockets. | ||
+ | |||
+ | if ((so = socket(AF_INET, | ||
+ | if (connect(so, | ||
+ | if (send(so, "GET / HTTP/ | ||
+ | if ((s = recv(so)) == NULL) exit(4); | ||
+ | |||
+ | printf(" | ||
+ | s = right(s, strlen(s) - p - 1); | ||
+ | |||
+ | while ((p = strchr(s, " | ||
+ | h = left(s, p); | ||
+ | hp = strstr(h, ": " | ||
+ | l = left(h, hp); | ||
+ | r = substr(h, hp + 2, strlen(s)-hp-2-1); | ||
+ | printf(" | ||
+ | s = right(s, strlen(s) - p - 1); | ||
+ | } | ||
+ | printf(" | ||
+ | close(s); | ||
+ | exit(0); | ||
</ | </ |