test code. request http get method to google, and write http responce to localdisk

Dependencies:   mbed lwip

Committer:
ytsuboi
Date:
Wed Mar 31 17:22:18 2010 +0000
Revision:
0:9cfb40721100

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ytsuboi 0:9cfb40721100 1 #include "mbed.h"
ytsuboi 0:9cfb40721100 2 // import Library from http://mbed.org/projects/cookbook/svn/EMAC/lwip/trunk
ytsuboi 0:9cfb40721100 3 // Name: HTTPClient
ytsuboi 0:9cfb40721100 4 #include "HTTPClient.h"
ytsuboi 0:9cfb40721100 5
ytsuboi 0:9cfb40721100 6 DigitalOut led(LED1);
ytsuboi 0:9cfb40721100 7
ytsuboi 0:9cfb40721100 8 // see http://mbed.org/projects/cookbook/api/EMAC/lwip/trunk/HTTPClient/HTTPClient#HTTPClient.HTTPClientd
ytsuboi 0:9cfb40721100 9 HTTPClient http("wolf", // Brings up the device with static IP address and domain name.
ytsuboi 0:9cfb40721100 10 IPv4(192,168,15,123), // IPv4 address
ytsuboi 0:9cfb40721100 11 IPv4(255,255,255,0), // netmask
ytsuboi 0:9cfb40721100 12 IPv4(192,168,15,2), // default gateway
ytsuboi 0:9cfb40721100 13 IPv4(192,168,15,2)); // dns server
ytsuboi 0:9cfb40721100 14
ytsuboi 0:9cfb40721100 15 LocalFileSystem local("local");
ytsuboi 0:9cfb40721100 16 /**
ytsuboi 0:9cfb40721100 17 * Request a google search for HelloWorld and display the first 2000 characters
ytsuboi 0:9cfb40721100 18 * of the page source on the serial terminal.
ytsuboi 0:9cfb40721100 19 */
ytsuboi 0:9cfb40721100 20 int main(void) {
ytsuboi 0:9cfb40721100 21 char url[256];
ytsuboi 0:9cfb40721100 22
ytsuboi 0:9cfb40721100 23 // Open a file to write.
ytsuboi 0:9cfb40721100 24 FILE *fd = fopen("/local/hello.htm", "w");
ytsuboi 0:9cfb40721100 25
ytsuboi 0:9cfb40721100 26 // Insert the search term into the URL
ytsuboi 0:9cfb40721100 27 sprintf(url, "http://www.google.co.jp/search?hl=en&q=%s&btnG=Search&meta=", "HelloWorld");
ytsuboi 0:9cfb40721100 28
ytsuboi 0:9cfb40721100 29 // Request a page and store it into a file.
ytsuboi 0:9cfb40721100 30 http.get(url, fd);
ytsuboi 0:9cfb40721100 31
ytsuboi 0:9cfb40721100 32 // Close the file.
ytsuboi 0:9cfb40721100 33 fclose(fd);
ytsuboi 0:9cfb40721100 34
ytsuboi 0:9cfb40721100 35 // The file is written on the local disk.
ytsuboi 0:9cfb40721100 36 // "/hello.htm" Have a look.
ytsuboi 0:9cfb40721100 37
ytsuboi 0:9cfb40721100 38 // Work is done!
ytsuboi 0:9cfb40721100 39 while(1) {
ytsuboi 0:9cfb40721100 40 led = !led;
ytsuboi 0:9cfb40721100 41 wait(0.2);
ytsuboi 0:9cfb40721100 42 }
ytsuboi 0:9cfb40721100 43 }