Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
sdk:httpget [2015/07/02 13:02]
fachet created
sdk:httpget [2015/07/02 13:34]
fachet
Line 7: Line 7:
 if (send(s, "GET / HTTP/​1.0\r\n\r\n"​) == -1) exit(3); if (send(s, "GET / HTTP/​1.0\r\n\r\n"​) == -1) exit(3);
 if ((r = recv(s)) == NULL) exit(4); if ((r = recv(s)) == NULL) exit(4);
-printf("​%s",​ r);+printf("​%s\n", r); 
 +if (!strstr(r, "​HTTP/​1.1 200 OK")) { 
 +   i = substr(r, strstr(r, "IP Address: ") + 12, strlen(r));​ 
 +   ​printf("​IP Address: %s\n", left(i, strstr(i, "</​body>"​)));​ 
 +}
 close(s); close(s);
 +exit(0);
 </​code>​ </​code>​
  
 <code c Output> <code c Output>
- 
 HTTP/1.1 200 OK HTTP/1.1 200 OK
 Content-Type:​ text/html Content-Type:​ text/html
Line 23: Line 27:
 <​html><​head><​title>​Current IP Check</​title></​head><​body>​Current IP Address: 89.12.4.18</​body></​html>​ <​html><​head><​title>​Current IP Check</​title></​head><​body>​Current IP Address: 89.12.4.18</​body></​html>​
  
 +IP Address: 89.12.4.18
 </​code>​ </​code>​