我正在尝试使用libevent来模拟多个HTTP客户端。以下代码片段有效但不幸的是它似乎不支持HTTP重做(301,302)。想知道它是否受libevent HTTP包的支持,如果是的话,我该如何启用它。
提前致谢。
void http_request_done(struct evhttp_request *req, void *arg){
printf("http_request_done\n");
}
int http_req(char *uri, int i) {
struct evhttp_connection *conn = evhttp_connection_base_new(base, NULL, host, port);
struct evhttp_request *req = evhttp_request_new(http_request_done, base);
req->cb_arg = (void*) i;
evhttp_add_header(req->output_headers, "Host", "localhost");
evhttp_add_header(req->output_headers, "Connection", "KeepAlive");
evhttp_make_request(conn, req, EVHTTP_REQ_GET, uri);
}
答案 0 :(得分:2)
结束在http_request_done()函数中手动执行:
void http_request_done(struct evhttp_request *req, void *arg){
const char *url = evhttp_find_header(evhttp_request_get_input_headers(req), "Location");
if (url) {
quickHttpRequest(id, (char*) url);
return;
}
...
}