用libevent evhttp流客户端请求体?

我想用libevent和evhttp流式传输客户端POST请求主体。 我已经找到了使用固定主体发送请求的示例,但我不确定如何使用正文设置请求,我将需要在不确定的时间段内连续写入和更新。 有可能这样做会解放吗? 我目前的代码基线看起来像这样:

#include  #include  #include  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请求?

LibEvent为此设置了function。 你可以看到像这样的代码示例

我们可以在文档中看到那些函数 – 在start()/ end()之间的循环中的chunk():`

evhttp_send_reply_start (struct evhttp_request * req)

evhttp_send_reply_chunk (struct evhttp_request * req,struct evbuffer * databuf)

evhttp_send_reply_end (struct evhttp_request * req)`。

这些是用于发送,如果你需要获取传入的分块数据,则有evhttp_request_set_chunked_cb()