#include "httpclient.h" #include "string.h" #include "stdio.h" #include "main.h" #include "sys_http.h" #include "log.h" #include "gd32_flash.h" #include "netconf.h" //http配置标志位 uint8_t load_http_config=0; //get请求 http://gpu.ringzle.com:8082/iot/transmit/getTransmitConfig/DT8pd3ac6h 端口8082 //目前为此处去控制http一次性读入数据大小,应为该处为读入函数 void http_getDemo(void) { int datalen; int ret; while(dhcp_done != 1) { vTaskDelay(100); } char *device_config=pvPortMalloc(10); memset(device_config, 0,10); read_data_from_flash(device_config); if((strstr(device_config,"tcp_config")) == NULL) { // LogPrint(LOG_INFO,__FILE__,__FUNCTION__,__LINE__,"HTTP Get config"); char *http_data=pvPortMalloc(10 * 1024); // 接收数据上限为25K char *http=pvPortMalloc(50); sprintf(http,"/iot/transmit/getTransmitConfig/%s",gatewayId); ret = http_clientGet("gpu.ringzle.com", http, 8082, 0, http_data, &datalen); if(ret==200) //获取成功 { // LogPrint(LOG_INFO,__FILE__,__FUNCTION__,__LINE__,"HTTP Get config success"); // sprintf(http_data,"tcp_config"); save_config_params(http_data); load_http_config=1; } vPortFree(http_data); vPortFree(http); } vPortFree(device_config); } char *postData = "{\"bandwidth\":250,\"codeRate\":4700}"; uint8_t postResult[512]; //POST请求 http://gpu.ringzle.com/iot/test/httpTest 端口号8082 void http_postDemo(void) { int datalen, ret; memset(postResult, 0, sizeof(postResult)); // ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, http_data, 5837, postResult, &datalen); ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, (uint8_t *)postData, strlen(postData), postResult, &datalen); HTTP_PRINTF("%s", (char *)postResult); HTTP_PRINTF("\r\n ret=%d datalen=%d\r\n", ret, datalen); } /* ********************************************************************************************************* * 函 数 名: int get_http_config(void) * 功能说明: 获取http配置的相关参数 * 形 参:无 * 返 回 值: 返回http是否配置 0:没有配置过,1:配置过 ********************************************************************************************************* */ int get_http_config(void) { return load_http_config; }