Hi, I am using Mongoose 3.0 and ran "test/embed.c" to check for POST request data. I was expecting function test_post() would return "aaaaaaaaa" but it returns some funny characters. How can I get request data sent along with POST request? Am I missing something? Does it has do do something with "Content-Type" field?
*Compile embed.c* # cc -g -o ./embed test/embed.c mongoose.c -I. -pthread -DNO_SSL -DLISTENING_PORT=\"23456\" #./embed *Run curl to send POST requests* # cat /root/data aaaaaaaaa # curl -X POST -H "X-Auth-Token:puneet_token" -d @/root/data http://localhost:23456/test_post $�� # curl -X POST -H "Content-Type: text/html" -H "X-Auth-Token:puneet_token" -d @/root/data http://localhost:23456/test_post $�� # curl -X POST -H "Content-Type: text/plain" -H "X-Auth-Token:puneet_token" -d @/root/data http://localhost:23456/test_post $�� *Snippet from embed.c* ::: static void test_post(struct mg_connection *conn, const struct mg_request_info *ri) { const char *cl; char *buf; int len; mg_printf(conn, "%s", standard_reply); if (strcmp(ri->request_method, "POST") == 0 && (cl = mg_get_header(conn, "Content-Length")) != NULL) { len = atoi(cl); if ((buf = malloc(len)) != NULL) { mg_write(conn, buf, len); printf("buf: %s\n", buf); free(buf); } } } static const struct test_config { enum mg_event event; const char *uri; void (*func)(struct mg_connection *, const struct mg_request_info *); } test_config[] = { {MG_NEW_REQUEST, "/test_get_header", &test_get_header}, {MG_NEW_REQUEST, "/test_get_var", &test_get_var}, {MG_NEW_REQUEST, "/test_get_request_info", &test_get_request_info}, {MG_NEW_REQUEST, "/test_post", &test_post}, {MG_HTTP_ERROR, "", &test_error}, {0, NULL, NULL} }; static void *callback(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) { int i; for (i = 0; test_config[i].uri != NULL; i++) { if (event == test_config[i].event && (event == MG_HTTP_ERROR || !strcmp(request_info->uri, test_config[i].uri))) { test_config[i].func(conn, request_info); return "processed"; } } return NULL; } int main(void) { struct mg_context *ctx; const char *options[] = {"listening_ports", LISTENING_PORT, NULL}; ctx = mg_start(callback, NULL, options); pause(); return 0; } Regards, ~Puneet -- You received this message because you are subscribed to the Google Groups "mongoose-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/mongoose-users. For more options, visit https://groups.google.com/d/optout.
