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