中级会员
 
- 积分
- 216
- 金钱
- 216
- 注册时间
- 2016-11-3
- 在线时间
- 43 小时
|
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; // 森曹講峈掛ウ赻撩婓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; // 森曹講峈掛ウ赻撩婓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
|
|