CppHttpDemo icon indicating copy to clipboard operation
CppHttpDemo copied to clipboard

http-client 严重问题

Open Fauny opened this issue 4 years ago • 2 comments

原生demo的http-client 连续发的两个请求,handle_func仅执行了一次。

Fauny avatar Nov 22 '20 02:11 Fauny

我也遇到了同样的问题,请问有解决方案吗?

Harry-YYM avatar Jan 17 '22 12:01 Harry-YYM

刚才我自己试了一下,在SendReq函数的最后增加一行代码退出当前连接即可: void HttpClient::SendReq(const std::string &url, const std::string &content, ReqCallback req_callback) {

s_req_callback = req_callback;
mg_mgr mgr;
mg_mgr_init(&mgr, NULL);
auto connection = mg_connect_http(&mgr, OnHttpEvent, url.c_str(), NULL, content.c_str());
mg_set_protocol_http_websocket(connection);

printf("Send http request %s\n", url.c_str());

// loop
while (s_exit_flag == 0)
	mg_mgr_poll(&mgr, 500);

mg_mgr_free(&mgr);
s_exit_flag = 0;//增加这一行即可

}

Harry-YYM avatar Jan 17 '22 12:01 Harry-YYM