Daniel Peter
/
cig_httpclient2
main.cpp@1:41024576e6e2, 2011-05-30 (annotated)
- Committer:
- mbed714
- Date:
- Mon May 30 15:06:52 2011 +0000
- Revision:
- 1:41024576e6e2
- Parent:
- 0:55680e5cc478
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed714 | 0:55680e5cc478 | 1 | #include "mbed.h" |
mbed714 | 0:55680e5cc478 | 2 | #include "EthernetNetIf.h" |
mbed714 | 0:55680e5cc478 | 3 | #include "HTTPClient.h" |
mbed714 | 0:55680e5cc478 | 4 | |
mbed714 | 0:55680e5cc478 | 5 | EthernetNetIf eth; //(IpAddr(160,48,199,80),IpAddr(255,255,255,128),IpAddr(0,0,0,0),IpAddr(0,0,0,0)); |
mbed714 | 0:55680e5cc478 | 6 | |
mbed714 | 0:55680e5cc478 | 7 | HTTPClient http; |
mbed714 | 0:55680e5cc478 | 8 | HTTPText txt; |
mbed714 | 0:55680e5cc478 | 9 | |
mbed714 | 0:55680e5cc478 | 10 | void HTTPGetCallbackEvent(HTTPResult result) { |
mbed714 | 0:55680e5cc478 | 11 | |
mbed714 | 0:55680e5cc478 | 12 | int iRetValue = http.getHTTPResponseCode(); |
mbed714 | 0:55680e5cc478 | 13 | |
mbed714 | 0:55680e5cc478 | 14 | printf("HTTPGetCallbackEvent->Result: %d \r\n", iRetValue); |
mbed714 | 0:55680e5cc478 | 15 | |
mbed714 | 0:55680e5cc478 | 16 | if (result==HTTP_OK) { |
mbed714 | 0:55680e5cc478 | 17 | // printf("Result :\"%s\"\r\n", txt.gets()); |
mbed714 | 0:55680e5cc478 | 18 | printf("Result ok : %s\n", txt.gets()); |
mbed714 | 0:55680e5cc478 | 19 | //printf("Result :ok\r\n"); |
mbed714 | 0:55680e5cc478 | 20 | } else { |
mbed714 | 0:55680e5cc478 | 21 | printf("Error %d\r\n", result); |
mbed714 | 0:55680e5cc478 | 22 | } |
mbed714 | 0:55680e5cc478 | 23 | } |
mbed714 | 0:55680e5cc478 | 24 | |
mbed714 | 0:55680e5cc478 | 25 | |
mbed714 | 0:55680e5cc478 | 26 | |
mbed714 | 0:55680e5cc478 | 27 | int main() { |
mbed714 | 0:55680e5cc478 | 28 | |
mbed714 | 0:55680e5cc478 | 29 | printf("Setting up...\r\n"); |
mbed714 | 0:55680e5cc478 | 30 | EthernetErr ethErr = eth.setup(); |
mbed714 | 0:55680e5cc478 | 31 | if (ethErr) { |
mbed714 | 0:55680e5cc478 | 32 | printf("Error %d in setup.\r\n", ethErr); |
mbed714 | 0:55680e5cc478 | 33 | return -1; |
mbed714 | 0:55680e5cc478 | 34 | } |
mbed714 | 0:55680e5cc478 | 35 | printf("Setup OK\r\n"); |
mbed714 | 0:55680e5cc478 | 36 | |
mbed714 | 0:55680e5cc478 | 37 | |
mbed714 | 0:55680e5cc478 | 38 | |
mbed714 | 0:55680e5cc478 | 39 | |
mbed714 | 0:55680e5cc478 | 40 | // http.setRequestHeader("Connection", "Keep-Alive"); |
mbed714 | 0:55680e5cc478 | 41 | |
mbed714 | 0:55680e5cc478 | 42 | printf("Send message\r\n"); |
mbed714 | 0:55680e5cc478 | 43 | |
mbed714 | 0:55680e5cc478 | 44 | |
mbed714 | 0:55680e5cc478 | 45 | HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt, HTTPGetCallbackEvent); |
mbed714 | 0:55680e5cc478 | 46 | // HTTPResult r = http.get("http://160.48.199.50/r?b=1&r=0&s=1", &txt, HTTPGetCallbackEvent); |
mbed714 | 0:55680e5cc478 | 47 | |
mbed714 | 0:55680e5cc478 | 48 | while (1) { |
mbed714 | 0:55680e5cc478 | 49 | //printf("alive\r\n"); |
mbed714 | 0:55680e5cc478 | 50 | Net::poll(); |
mbed714 | 0:55680e5cc478 | 51 | } |
mbed714 | 0:55680e5cc478 | 52 | |
mbed714 | 0:55680e5cc478 | 53 | return 0; |
mbed714 | 0:55680e5cc478 | 54 | |
mbed714 | 0:55680e5cc478 | 55 | } |
mbed714 | 0:55680e5cc478 | 56 |