【发布时间】:2017-03-03 09:55:00
【问题描述】:
我想使用 libevent 和 evhttp 流式传输客户端 POST 请求正文。我找到了发送带有固定正文的请求的示例,但不确定如何设置带有正文的请求,我需要在不确定的时间内持续编写和更新。是否有可能做到这一点?我当前的代码基线如下所示:
#include <evhttp.h>
#include <event2/event.h>
#include <event2/http.h>
void http_request_done(struct evhttp_request *req, void *arg) {
printf("DONE!\n");
}
int main(int argc, char **argv) {
struct event_base *base = event_base_new();
struct evhttp_connection *conn = evhttp_connection_base_new(base, NULL, "127.0.0.1", 3000);
struct evhttp_request *req = evhttp_request_new(http_request_done, NULL);
evhttp_make_request(conn, req, EVHTTP_REQ_POST, "/");
evhttp_connection_set_timeout(req->evcon, 600);
event_base_loop(base, EVLOOP_NONBLOCK);
event_base_dispatch(base);
return 0;
}
如何发送带有流式正文的 POST 请求?
【问题讨论】: