CppHttpDemo icon indicating copy to clipboard operation
CppHttpDemo copied to clipboard

httpClient

Open huangshangbin opened this issue 6 years ago • 1 comments

why not have post request

huangshangbin avatar Jun 19 '19 03:06 huangshangbin

support post-request, and need to develop by yourself

void HttpClient::SendReq(const std::string &url, const std::string &post_data, 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, post_data.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);
}

but mg_connect_http() has bug where post-data has '\0', need to modify.

cherishman2005 avatar Dec 15 '21 12:12 cherishman2005