Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include "mbed.h"
  2. #include "EthernetInterface.h"
  3. #include "HTTPClient.h"
  4. #include "getline.h"
  5. #include "IHTTPData.h"
  6.  
  7. EthernetInterface eth;
  8. HTTPClient http;
  9.  
  10. size_t data_out_len;
  11.  
  12. char recvBuff[1024*20];
  13. char http_post[10]="name=peter";
  14. void net_main(void const *av)
  15. {
  16.     int ret ;
  17.     char post_get[20];
  18.     char url[100];
  19.     HTTPText http_data_out(http_post);
  20.     HTTPText http_data_in(recvBuff);
  21.     printf("\n\rpost=%s\n\r",http_post);
  22.         eth.init(); //Use DHCP
  23.     printf("HTTP Client, Starting,...\n\r") ;
  24.     while(1) {
  25.         if(eth.connect() == 0)break ;
  26.         printf("Retry\n\r") ;
  27.     }
  28.   //  http.dumpReqHeader(false);
  29.   //  http.dumpResHeader(false);
  30.     while(1) {
  31.         getline("URL: ", url, sizeof(url)) ;
  32.         if(strlen(url) == 0)return ;
  33.         /*** HTTP ***/
  34.         getline("\n\rPOST OR GET: ",post_get,sizeof(post_get));
  35.         if(!strcmp(post_get,"post"))
  36.         {
  37.             ret=http.post(url,http_data_out,&http_data_in);
  38.                         printf("\r\nret=%d\r\nResult1=%s\n\r",ret,recvBuff);
  39.         }
  40.         else if (!strcmp(post_get,"get"))
  41.         {
  42.             ret = http.get(url, recvBuff, sizeof(recvBuff));
  43.         }
  44.         else
  45.            printf("wrong input\r\n");
  46.        
  47.                 if (!ret) {
  48.             printf("Result: %s\n\r", recvBuff);
  49.         } else {
  50.             printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode());
  51.         }
  52.     }
  53. }
  54.  
  55. int main(void)
  56. {
  57. #define STACK_SIZE 24000
  58.     Thread t(net_main, NULL, osPriorityNormal, STACK_SIZE);
  59.     while (true) {
  60.         Thread::wait(1000);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement