OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 6753|回复: 3

請教大神,STM32 LWIP 如何實現 HTTP POST ?

[复制链接]

13

主题

37

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
216
金钱
216
注册时间
2016-11-3
在线时间
43 小时
发表于 2016-12-27 14:36:58 | 显示全部楼层 |阅读模式
1金钱

啓奏各位大神
為了實現 HTTP POST (因為幾乎沒有人再用 CGI 了嘛 .... ),所以小弟參考了這個文件  http://blog.csdn.net/pugu12/article/details/41943565

可是小弟初學軟件,明明照抄一個字都沒錯,卻編譯不出來,一堆錯誤,都急的哭出來了!
口有大神願意出手相救?
拜謝,付費求解我都願意!

err_t httpd_post_begin(void *connection, const char *uri, const char *http_request,
                       u16_t http_request_len, int content_len, char *response_uri,
                       u16_t response_uri_len, u8_t *post_auto_wnd)
{

#if LWIP_HTTPD_CGI
  int i = 0;
#endif

struct http_state *hs = (struct http_state *)connection;

if(!uri || (uri[0] == '\0')) {
    return ERR_ARG;
}

hs->cgi_handler_index = -1;   // 此变量为本人自己在struct http_state 添加 用于保存CGI handler 索引 为-1表示无CGI handler索引
hs->response_file = NULL; // 此变量为本人自己在struct http_state 添加 用于保存 CGI handler 处理完后返回的响应uri.

#if LWIP_HTTPD_CGI

  if (g_iNumCGIs && g_pCGIs) {
    for (i = 0; i < g_iNumCGIs; i++) {
      if (strcmp(uri, g_pCGIs.pcCGIName) == 0) {
         hs->cgi_handler_index = i; // 找到响应的 CGI handler 将其保存在cgi_handler_index 以便在httpd_post_receive_data中使用
         break;
       }
    }
  }

  if(i == g_iNumCGIs) {
    return ERR_ARG; // 未找到CGI handler
  }
#endif
  return ERR_OK;
}

#define LWIP_HTTPD_POST_MAX_PAYLOAD_LEN     512
static char http_post_payload[LWIP_HTTPD_POST_MAX_PAYLOAD_LEN];
static u16_t http_post_payload_len = 0;
err_t httpd_post_receive_data(void *connection, struct pbuf *p)
{
    struct http_state *hs = (struct http_state *)connection;
    struct pbuf *q = p;
    int count;
    u32_t http_post_payload_full_flag = 0;
    while(q != NULL)  // 缓存接收的数据至http_post_payload
    {
      if(http_post_payload_len + q->len <= LWIP_HTTPD_POST_MAX_PAYLOAD_LEN) {
          MEMCPY(http_post_payload+http_post_payload_len, q->payload, q->len);
          http_post_payload_len += q->len;
      }
      else {  // 缓存溢出 置溢出标志位
        http_post_payload_full_flag = 1;
        break;
      }
      q = q->next;
    }
    pbuf_free(p); // 释放pbuf
    if(http_post_payload_full_flag) // 缓存溢出 则丢弃数据
    {
       http_post_payload_full_flag = 0;
       http_post_payload_len = 0;
       hs->cgi_handler_index = -1;
       hs->response_file = NULL;
    }
    else if(hs->post_content_len_left == 0) {  // POST数据已经接收完毕 则处理
        if(hs->cgi_handler_index != -1) {
            count = extract_uri_parameters(hs, http_post_payload);  // 解析
            hs->response_file = g_pCGIs[hs->cgi_handler_index].pfnCGIHandler(hs->cgi_handler_index, count, hs->params,
                                             hs->param_vals); // 调用解析函数
            http_post_payload_len = 0;
        }
        else {
            hs->response_file = NULL;
            http_post_payload_len = 0;
        }
    }
    return ERR_OK;
}

void httpd_post_finished(void *connection, char *response_uri, u16_t response_uri_len)
{
    struct http_state *hs = (struct http_state *)connection;
    if(hs->response_file != NULL) {
        strncpy(response_uri, hs->response_file,response_uri_len); // 拷贝uri 用于给浏览器响应相应的请求
    }
}

**************************************************************************************
錯誤訊息:
*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling httpd.c...
..\LWIP\lwip_app\web_server_demo\httpd.c(2243): error:  #136: struct "http_state"  has no field "cgi_handler_index"
   hs->cgi_handler_index = -1;   // 森曹講峈掛&#65395;赻撩婓struct http_state 氝樓 蚚衾悵湔CGI handler 坰竘 峈-1桶尨拸CGI handler坰竘
..\LWIP\lwip_app\web_server_demo\httpd.c(2244): error:  #136: struct "http_state"  has no field "response_file"
   hs->response_file = NULL; // 森曹講峈掛&#65395;赻撩婓struct http_state 氝樓 蚚衾悵湔 CGI handler 揭燴俇綴殿隙腔砒茼uri.
..\LWIP\lwip_app\web_server_demo\httpd.c(2251): error:  #136: struct "http_state"  has no field "cgi_handler_index"
           hs->cgi_handler_index = i; // 梑善砒茼腔 CGI handler 蔚[悵湔婓cgi_handler_index 眕晞婓httpd_post_receive_data笢妏蚚
..\LWIP\lwip_app\web_server_demo\httpd.c(2291): error:  #136: struct "http_state"  has no field "cgi_handler_index"
         hs->cgi_handler_index = -1;
..\LWIP\lwip_app\web_server_demo\httpd.c(2292): error:  #136: struct "http_state"  has no field "response_file"
         hs->response_file = NULL;
..\LWIP\lwip_app\web_server_demo\httpd.c(2295): error:  #136: struct "http_state"  has no field "cgi_handler_index"
          if(hs->cgi_handler_index != -1) {
..\LWIP\lwip_app\web_server_demo\httpd.c(2297): error:  #136: struct "http_state"  has no field "response_file"
              hs->response_file = g_pCGIs[hs->cgi_handler_index].pfnCGIHandler(hs->cgi_handler_index, count, hs->params,
..\LWIP\lwip_app\web_server_demo\httpd.c(2297): error:  #136: struct "http_state"  has no field "cgi_handler_index"
              hs->response_file = g_pCGIs[hs->cgi_handler_index].pfnCGIHandler(hs->cgi_handler_index, count, hs->params,
..\LWIP\lwip_app\web_server_demo\httpd.c(2297): error:  #136: struct "http_state"  has no field "cgi_handler_index"
              hs->response_file = g_pCGIs[hs->cgi_handler_index].pfnCGIHandler(hs->cgi_handler_index, count, hs->params,
..\LWIP\lwip_app\web_server_demo\httpd.c(2302): error:  #136: struct "http_state"  has no field "response_file"
              hs->response_file = NULL;
..\LWIP\lwip_app\web_server_demo\httpd.c(2312): error:  #136: struct "http_state"  has no field "response_file"
      if(hs->response_file != NULL) {
..\LWIP\lwip_app\web_server_demo\httpd.c(2313): error:  #136: struct "http_state"  has no field "response_file"
          strncpy(response_uri, hs->response_file,response_uri_len); // 蕭探uri 蚚衾跤銡擬け砒茼眈茼腔ワА
..\LWIP\lwip_app\web_server_demo\httpd.c: 0 warnings, 12 errors
compiling httpd_cgi_ssi.c...
compiling main.c...
"..\OBJ\Template.axf" - 12 Error(s), 0 Warning(s).
Target not created.
Build Time Elapsed:  00:00:01



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165426
金钱
165426
注册时间
2010-12-1
在线时间
2113 小时
发表于 2016-12-27 21:33:12 | 显示全部楼层
回复

使用道具 举报

12

主题

31

帖子

0

精华

新手上路

积分
40
金钱
40
注册时间
2011-5-30
在线时间
6 小时
发表于 2017-3-31 17:35:41 | 显示全部楼层
同样的问题,帮顶
回复

使用道具 举报

0

主题

174

帖子

0

精华

高级会员

Rank: 4

积分
725
金钱
725
注册时间
2016-1-9
在线时间
64 小时
发表于 2017-4-1 00:42:30 | 显示全部楼层
hs->cgi_handler_index = -1;   // 此变量为本人自己在struct http_state 添加 用于保存CGI handler 索引 为-1表示无CGI handler索引
hs->response_file = NULL; // 此变量为本人自己在struct http_state 添加 用于保存 CGI handler 处理完后返回的响应uri.
这两句话,你去  http_state  结构体定义的地方加上   response_file 和   cgi_handler_index  的定义试试
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-4-9 01:42

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表