A http client sample program.
Dependencies: NyFileSystems libMiMic mbed-rtos mbed
Fork of TcpSocketClientSamlpe by
Diff: main.cpp
- Revision:
- 28:dd350a9a5221
- Parent:
- 26:f58dc24e2c1b
--- a/main.cpp Wed Oct 23 04:53:25 2013 +0000 +++ b/main.cpp Tue Sep 15 09:28:25 2015 +0000 @@ -13,18 +13,18 @@ #include "fsdata.h" LocalFileSystem2 lf("local"); -NetConfig cfg; //create network configulation -Net* net; DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); + MiMicNetIf netif; + NetConfig cfg; //create network configulation with onchip-setting. int main() { - net=new Net();//Net constructor must be created after started RTOS + Net net(netif);//Net constructor must be created after started RTOS // manual setting cfg.setIpAddr(192,168,128,39); @@ -36,11 +36,12 @@ // Create http client. // Socket must create between "net.start" with "new Net()" HttpClient http; +led1=1; //Start network - net->start(cfg); - - if(http.connect(IpAddr(192,168,128,195),80)){ + net.start(cfg); +led2=2; + if(http.connect(IpAddr(192,168,128,1),80)){ if(http.sendMethod(HttpClient::HTTP_GET,"/mimic/")){ FILE *fp=fopen("/local/out.txt", "w"); if(fp!=NULL){ @@ -72,6 +73,21 @@ } http.close(); } + if(http.connect(IpAddr(192,168,128,254),80)){ + if(http.sendMethod(HttpClient::HTTP_POST,"/mimic/")){ + const char* DATA="{json}"; + if(http.write(DATA,strlen(DATA))){ + if(http.getStatus()==200){ + char buf[256]; + short len; + if(http.read(buf,256,len)){ + printf("%.*s",len,buf); + } + } + } + } + http.close(); + } for(int c=0;;c=(c+1)%2){ led4=c; Thread::wait(500);