This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
sdk:httpget [2015/07/02 13:20] fachet |
sdk:httpget [2015/07/02 14:15] (current) fachet |
||
---|---|---|---|
Line 13: | Line 13: | ||
} | } | ||
close(s); | close(s); | ||
+ | exit(0); | ||
</code> | </code> | ||
Line 28: | Line 28: | ||
IP Address: 89.12.4.18 | IP Address: 89.12.4.18 | ||
+ | </code> | ||
+ | | ||
+ | <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, SOCK_STREAM, IPPROTO_TCP)) < 0) exit(1); | ||
+ | if (connect(so, "checkip.dyndns.com", 80) < 0) exit(2); | ||
+ | if (send(so, "GET / HTTP/1.0\r\n\r\n") == -1) exit(3); | ||
+ | if ((s = recv(so)) == NULL) exit(4); | ||
+ | |||
+ | printf("RESPONSE: <%s>\n", left(s, p = strstr(s, "\n"))); | ||
+ | s = right(s, strlen(s) - p - 1); | ||
+ | |||
+ | while ((p = strchr(s, "\n")) > 0) { | ||
+ | h = left(s, p); | ||
+ | hp = strstr(h, ": "); | ||
+ | l = left(h, hp); | ||
+ | r = substr(h, hp + 2, strlen(s)-hp-2-1); | ||
+ | printf("HEADER: <%s> value <%s>\n", l, r); | ||
+ | s = right(s, strlen(s) - p - 1); | ||
+ | } | ||
+ | printf("BODY: %s\n", s); | ||
+ | close(s); | ||
+ | exit(0); | ||
</code> | </code> |