MCPcopy Create free account
hub / github.com/acl-dev/acl / send

Method send

app/master/tools/master_dispatch/server/status/HttpClient.cpp:33–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33bool HttpClient::send()
34{
35 // 创建 HTTP 请求客户端
36 acl::http_request req(server_addr_);
37 acl::http_header& hdr = req.request_header();
38
39 // 设置请求的 URL
40 hdr.set_url("/");
41
42 // 设置 HTTP 请求头的字段
43 hdr.set_content_type("text/json; charset=gb2312");
44 hdr.set_keep_alive(false);
45
46 // 发送数据体
47 if (req.request(buf_->c_str(), buf_->length()) == false)
48 {
49 logger_error("request to server error, addr: %s",
50 server_addr_.c_str());
51 return false;
52 }
53
54 int status = req.http_status();
55 if (status != 200)
56 {
57 logger_error("server(%s) return status: %d",
58 server_addr_.c_str(), status);
59 return false;
60 }
61
62 long long int length = req.body_length();
63 if (length <= 0)
64 return true;
65
66 // 将响应数据体读完
67 acl::string buf;
68 if (req.get_body(buf) == false)
69 {
70 logger_error("read response body failed!");
71 return false;
72 }
73
74 return true;
75}

Callers 4

tcp_reportMethod · 0.45
mFunction · 0.45
buildFunction · 0.45

Calls 9

request_headerMethod · 0.80
set_content_typeMethod · 0.80
set_keep_aliveMethod · 0.80
http_statusMethod · 0.80
requestMethod · 0.45
c_strMethod · 0.45
lengthMethod · 0.45
body_lengthMethod · 0.45
get_bodyMethod · 0.45

Tested by

no test coverage detected