Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http-client 严重问题 #7

Open
Fauny opened this issue Nov 22, 2020 · 2 comments
Open

http-client 严重问题 #7

Fauny opened this issue Nov 22, 2020 · 2 comments

Comments

@Fauny
Copy link

Fauny commented Nov 22, 2020

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

@Harry-YYM
Copy link

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

@Harry-YYM
Copy link

Harry-YYM commented Jan 17, 2022

刚才我自己试了一下,在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;//增加这一行即可

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants