#include <stdio.h>
#include <string.h>
#include "mongoose.h"
int SendResponse(const char *response, void *addInfo)
{
struct mg_connection *conn = (struct mg_connection *) addInfo;
if (mg_printf(conn, "HTTP/1.1 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s", strlen(response), response) > 0) {
return 1;
} else {
return 0;
}
}
int callback(struct mg_connection *conn)
{
const struct mg_request_info *request_info = mg_get_request_info(conn);
char *readBuffer = NULL;
int postSize = 0;
if (strcmp(request_info->request_method, "GET") == 0) {
SendResponse("hello world", conn);
printf("get \n");
return 1;
} else if (strcmp(request_info->request_method, "POST") == 0) {
//get size of postData
sscanf(mg_get_header(conn, "Content-Length"), "%d", &postSize);
printf("post %d\n", postSize);
//Mark the request as processed by our handler.
return 1;
} else {
return 0;
}
}
int main(void) {
struct mg_context *ctx;
const char *options[] = {"listening_ports", "8080,443s","ssl_certificate","ssl_cert.pem",NULL};
struct mg_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = callback;
ctx = mg_start(&callbacks, NULL, options);
printf(" started on port(s) %s with web root [%s]\n",
"a", mg_get_option(ctx, "listening_ports"));
getchar(); // Wait until user hits "enter"
printf("char \n");
mg_stop(ctx);
printf("bye\n");
return 0;
}
#include <string.h>
#include "mongoose.h"
int SendResponse(const char *response, void *addInfo)
{
struct mg_connection *conn = (struct mg_connection *) addInfo;
if (mg_printf(conn, "HTTP/1.1 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n"
"%s", strlen(response), response) > 0) {
return 1;
} else {
return 0;
}
}
int callback(struct mg_connection *conn)
{
const struct mg_request_info *request_info = mg_get_request_info(conn);
char *readBuffer = NULL;
int postSize = 0;
if (strcmp(request_info->request_method, "GET") == 0) {
SendResponse("hello world", conn);
printf("get \n");
return 1;
} else if (strcmp(request_info->request_method, "POST") == 0) {
//get size of postData
sscanf(mg_get_header(conn, "Content-Length"), "%d", &postSize);
printf("post %d\n", postSize);
//Mark the request as processed by our handler.
return 1;
} else {
return 0;
}
}
int main(void) {
struct mg_context *ctx;
const char *options[] = {"listening_ports", "8080,443s","ssl_certificate","ssl_cert.pem",NULL};
struct mg_callbacks callbacks;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.begin_request = callback;
ctx = mg_start(&callbacks, NULL, options);
printf(" started on port(s) %s with web root [%s]\n",
"a", mg_get_option(ctx, "listening_ports"));
getchar(); // Wait until user hits "enter"
printf("char \n");
mg_stop(ctx);
printf("bye\n");
return 0;
}