Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mbed.h"
- #include "EthernetInterface.h"
- #include "HTTPClient.h"
- #include "getline.h"
- #include "IHTTPData.h"
- EthernetInterface eth;
- HTTPClient http;
- size_t data_out_len;
- char recvBuff[1024*20];
- char http_post[10]="name=peter";
- void net_main(void const *av)
- {
- int ret ;
- char post_get[20];
- char url[100];
- HTTPText http_data_out(http_post);
- HTTPText http_data_in(recvBuff);
- printf("\n\rpost=%s\n\r",http_post);
- eth.init(); //Use DHCP
- printf("HTTP Client, Starting,...\n\r") ;
- while(1) {
- if(eth.connect() == 0)break ;
- printf("Retry\n\r") ;
- }
- // http.dumpReqHeader(false);
- // http.dumpResHeader(false);
- while(1) {
- getline("URL: ", url, sizeof(url)) ;
- if(strlen(url) == 0)return ;
- /*** HTTP ***/
- getline("\n\rPOST OR GET: ",post_get,sizeof(post_get));
- if(!strcmp(post_get,"post"))
- {
- ret=http.post(url,http_data_out,&http_data_in);
- printf("\r\nret=%d\r\nResult1=%s\n\r",ret,recvBuff);
- }
- else if (!strcmp(post_get,"get"))
- {
- ret = http.get(url, recvBuff, sizeof(recvBuff));
- }
- else
- printf("wrong input\r\n");
- if (!ret) {
- printf("Result: %s\n\r", recvBuff);
- } else {
- printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode());
- }
- }
- }
- int main(void)
- {
- #define STACK_SIZE 24000
- Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE);
- while (true) {
- Thread::wait(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement