sys_http.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "httpclient.h"
  2. #include "string.h"
  3. #include "stdio.h"
  4. #include "malloc.h"
  5. #include "main.h"
  6. #include "myFIle.h"
  7. #include "includes.h"
  8. #include "sys_http.h"
  9. #include "log.h"
  10. uint8_t load_http_config=0;
  11. //get请求 http://gpu.ringzle.com:8082/iot/transmit/getTransmitConfig/DT8pd3ac6h 端口8082
  12. //目前为此处去控制http一次性读入数据大小,应为该处为读入函数
  13. void http_getDemo(void)
  14. {
  15. int datalen;
  16. int ret;
  17. char *http_data=mymalloc(SRAMEX,60*1024);
  18. char *http=mymalloc(SRAMEX,50);
  19. sprintf(http,"/iot/transmit/getTransmitConfig/%s",gatewayId);
  20. ret = http_clientGet("gpu.ringzle.com", http, 8082, 0, http_data, &datalen);
  21. if(ret==200) //获取成功
  22. {
  23. DeleteDirFile("device.txt");
  24. write_file("device.txt",http_data,strlen(http_data));
  25. load_http_config=1;
  26. }
  27. HTTP_PRINTF("%s", (char *)http_data);
  28. HTTP_PRINTF("\r\n ret=%d datalen=%d\r\n", ret, datalen);
  29. LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "%s", (char *)http_data);
  30. LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "\r\n ret=%d datalen=%d\r\n", ret, datalen);
  31. myfree(SRAMEX,http_data);
  32. myfree(SRAMEX,http);
  33. }
  34. char *postData = "{\"bandwidth\":250,\"codeRate\":4700}";
  35. uint8_t postResult[512];
  36. //POST请求 http://gpu.ringzle.com/iot/test/httpTest 端口号8082
  37. void http_postDemo(void)
  38. {
  39. int datalen, ret;
  40. memset(postResult, 0, sizeof(postResult));
  41. // ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, http_data, 5837, postResult, &datalen);
  42. ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, (uint8_t *)postData, strlen(postData), postResult, &datalen);
  43. HTTP_PRINTF("%s", (char *)postResult);
  44. HTTP_PRINTF("\r\n ret=%d datalen=%d\r\n", ret, datalen);
  45. }
  46. /*
  47. *********************************************************************************************************
  48. * 函 数 名: int get_http_config(void)
  49. * 功能说明: 获取http配置的相关参数
  50. * 形 参:无
  51. * 返 回 值: 返回http是否配置 0:没有配置过,1:配置过
  52. *********************************************************************************************************
  53. */
  54. int get_http_config(void)
  55. {
  56. return load_http_config;
  57. }