A http client sample program.
Dependencies: NyFileSystems libMiMic mbed-rtos mbed
Fork of TcpSocketClientSamlpe by
main.cpp
- Committer:
- nyatla
- Date:
- 2013-04-28
- Revision:
- 5:6a2a1644ea2c
- Parent:
- 4:0a280ed0a848
- Child:
- 6:20dcb08e1b43
File content as of revision 5:6a2a1644ea2c:
/** * @file * This is ModLocalFileSystem sample program. * * <pre> * 1. Compile this program and write to your mbed. * 2. Write files for testing to mbed disk. * 2. Access via web browser to http://192.168.0.39/local/<filename> * 3. You can see <filename> file on browser. * </pre> */ #include "mbed.h" #include "SDFileSystem.h" #include "mimic.h" /** * local filesystem support. */ LocalFileSystem lf("local"); SDFileSystem sd(p5, p6, p7, p8,"sd"); /** * MiMic RemoteMCU httpd.<br/> * Number of simultaneous connections:4 * <p>Service list</p> * <pre> * /local/ - mbed LocalFileSystem * </pre> */ class FsHttpd:public MiMic::Httpd { private: ModLocalFileSystem modlocal; ModLocalFileSystem modsd; public: FsHttpd():Httpd(80) { //bind local file system path to /local/* modlocal.setParam("local"); modsd.setParam("sd"); } virtual void onRequest(HttpdConnection& i_connection) { //try to ModLocalFileSystem if(this->modlocal.execute(i_connection)){ return; } //try to ModLocalFileSystem(SD) if(this->modsd.execute(i_connection)){ return; } //Otherwise, Send simple top index page. i_connection.sendHeader(200,"text/html",NULL); if(i_connection.isMethodType(Http::MT_GET)){ i_connection.sendBodyF( "<!DOCTYPE html>" "<html lang=\"ja\">" "<head></head>" "<body>" "<h1>This is MiMic Server!</h1>" "<hr/>" "<ul>" "<li><a href=\"/local/\">mbed Local Filesystem</a></li>" "<li><a href=\"/sd/\">SDCard</a></li>" "</ul></body>"); } } }; int main() { NetConfig cfg; //create network configulation Net net(cfg); //create a net instance. //try to override setting by local file. if(!cfg.loadFromFile("/local/mimic.cfg")){ cfg.loadFromFile("/sd/mimic.cfg"); } FsHttpd httpd; //create a httpd instance. httpd.loop(); //start httpd loop. return 0; }