mongoose如何发送html页面,html - Mongoose C++: How to parse HTTP GET or POST request using mongoose? - Stac...

I am trying to create a simple c++ web-based GUI. I am not interested in using Qt or Visual Studio based GUI. I am rather interested in web based as my requirements are very minimal and basic.

So I came across "Mongoose" the C-based web server. After going through the examples I cooked up some code but it's not working as I have almost zero knowledge about internet programming. I was wondering if any of you have a simple example where I can retrieve the user data from the HTML form either using POST or GET request.

Here is what I have managed so far:

//

#include

#include

#include

#include "mongoose.h"

static const char *s_http_port = "8000";

volatile bool kill_server = FALSE;

struct mg_mgr mgr;

struct mg_connection *nc;

bool control1_triggered = FALSE;

bool control2_triggered = FALSE;

struct file_writer_data {

FILE *fp;

size_t bytes_written;

};

static void handle_upload(struct mg_connection *nc, int ev, void *p) {

printf("Signal received! %d\n", ev);

control1_triggered = TRUE;

struct mg_http_multipart_part *mp = (struct mg_http_multipart_part *) p;

printf(mp->data.p);

switch (ev) {

case MG_EV_HTTP_PART_DATA:

break;

}

}

static void handle_upload2(struct mg_connection *nc, int ev, void *p) {

printf("Signal received@2! %d\n", ev);

control2_triggered = TRUE;

}

void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {

(void)ev_data;

switch (ev) {

case MG_EV_HTTP_REQUEST:

// Invoked when the full HTTP request is in the buffer (including body).

mg_printf(nc, "%s",

"HTTP/1.1 200 OK\r\n"

"Content-Type: text/html\r\n"

"Connection: close\r\n"

"\r\n"

"

Controls"

"

" enctype=\"multipart/form-data\">"

""

""

"

"

"

" enctype=\"multipart/form-data\">"

""

"

"

"input.search{width: 20em; height: 2em;}"

"");

nc->flags |= MG_F_SEND_AND_CLOSE;

break;

}

}

int main() {

mg_mgr_init(&mgr, NULL);

nc = mg_bind(&mgr, s_http_port, ev_handler);

mg_register_http_endpoint(nc, "/upload", handle_upload);

mg_register_http_endpoint(nc, "/Kill", handle_upload2);

// Set up HTTP server parameters

mg_set_protocol_http_websocket(nc);

while (1);

return 0;

}

Please note I have been googling around 3 days now, have seen most of the links and questions. But not a lot of support with Mongoose

Could you please help me with an example on how to parse GET or POST HTML request using Mongoose ?

Thank you so much.

Cheers,

Avi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值