00001 #include "mbed.h"00002 // import Library from http://mbed.org/projects/cookbook/svn/EMAC/lwip/trunk00003 // Name: HTTPClient00004 #include "HTTPClient.h"00005
00006 DigitalOut led(LED1);
00007
00008 // see http://mbed.org/projects/cookbook/api/EMAC/lwip/trunk/HTTPClient/HTTPClient#HTTPClient.HTTPClientd00009 HTTPClient http("wolf", // Brings up the device with static IP address and domain name.00010 IPv4(192,168,15,123), // IPv4 address00011 IPv4(255,255,255,0), // netmask00012 IPv4(192,168,15,2), // default gateway00013 IPv4(192,168,15,2)); // dns server00014
00015 LocalFileSystem local("local");
00016 /**00017 * Request a google search for HelloWorld and display the first 2000 characters 00018 * of the page source on the serial terminal.00019 */00020 int main(void) {
00021 char url[256];
00022
00023 // Open a file to write.00024 FILE *fd = fopen("/local/hello.htm", "w");
00025
00026 // Insert the search term into the URL00027 sprintf(url, "http://www.google.co.jp/search?hl=en&q=%s&btnG=Search&meta=", "HelloWorld");
00028
00029 // Request a page and store it into a file.00030 http.get(url, fd);
00031
00032 // Close the file.00033 fclose(fd);
00034
00035 // The file is written on the local disk.00036 // "/hello.htm" Have a look.00037
00038 // Work is done!00039 while(1) {
00040 led = !led;
00041 wait(0.2);
00042 }
00043 }