HTTPClient using static IP
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPClient.h" 00004 00005 EthernetNetIf eth(IpAddr(160,48,199,80),IpAddr(255,255,255,128),IpAddr(0,0,0,0),IpAddr(0,0,0,0)); 00006 00007 HTTPClient http; 00008 00009 void HTTPGetCallbackEvent(HTTPResult result) 00010 { 00011 00012 int iRetValue = http.getHTTPResponseCode(); 00013 00014 printf("HTTPGetCallbackEvent->Result: %d \r\n", iRetValue); 00015 00016 if(result==HTTP_OK) 00017 { 00018 // printf("Result :\"%s\"\r\n", txt.gets()); 00019 printf("Result :ok\r\n"); 00020 } 00021 else 00022 { 00023 printf("Error %d\r\n", result); 00024 } 00025 } 00026 00027 00028 00029 int main() { 00030 00031 printf("Setting up...\r\n"); 00032 EthernetErr ethErr = eth.setup(); 00033 if(ethErr) 00034 { 00035 printf("Error %d in setup.\r\n", ethErr); 00036 return -1; 00037 } 00038 printf("Setup OK\r\n"); 00039 00040 HTTPText txt; 00041 00042 00043 // http.setRequestHeader("Connection", "Keep-Alive"); 00044 00045 printf("Send message\r\n"); 00046 00047 00048 // HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt); 00049 HTTPResult r = http.get("http://160.48.199.50/r?b=1&r=0&s=1", &txt, HTTPGetCallbackEvent); 00050 00051 while(1) 00052 { 00053 //printf("alive\r\n"); 00054 Net::poll(); 00055 } 00056 00057 return 0; 00058 00059 } 00060
Generated on Tue Jul 12 2022 19:12:16 by
1.7.2