[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] bad request with evhttp libevent-2.0.10



Hi all.
I setup a simple httpd like this:

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include <err.h>
#include <event2/event.h>
#include <event2/http.h>
#include <event2/buffer.h>

void now_handler(struct evhttp_request *req, void *arg) {
    struct evbuffer *buf = evhttp_request_get_output_buffer(req);
    evbuffer_add_printf(buf, "{\"now\":%d}", (int) time(NULL));
    evhttp_send_reply(req, HTTP_OK, "OK", NULL);
}

int main(int argc, char **argv) {
    struct evhttp *httpd;

    struct event_base *base = event_base_new();
    httpd = evhttp_new(base);
    evhttp_bind_socket(httpd, "0.0.0.0", 8980);
    evhttp_set_gencb(httpd, now_handler, NULL);
    event_base_dispatch(base);
    /* Not reached in this code as it is now. */
    evhttp_free(httpd);

    return 0;
}

I got a "bad request" response when use firefox to request server with url: http://localhost:8980/_zc.1.gif?_domain=http://enbac.com/Thoi-trang-Nu/p742072/HANG-MOI-VE-NONG-HOI-3-1-4-1-Gio-quang-chau-lien-tuc-update-nhung-mau-THU-DONG-HOT-NHAT-1-tuan-hang-moi-ve-1-lan.html&_ci=1002121|59234,1001766|58380,1002143|59286&_zid=368  
please help me to fix it.
Thanks