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

Method http_request

lib_acl_cpp/samples/ssl/https_client/https_client.cpp:72–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72int https_client::http_request(int count)
73{
74 acl::http_client* client = new acl::http_client;
75
76 if (connect_server(*client) == false)
77 {
78 delete client;
79 return 0;
80 }
81
82 acl::http_header header;
83 header.set_url("/")
84 .accept_gzip(accept_gzip_)
85 .add_entry("Accept-Languge", "zh-cn,en;q=0.5")
86 .set_host(domain_.c_str())
87 .set_keep_alive(keep_alive_);
88
89 char buf[8192];
90 int i = 0;
91
92 for (; i < count; i++)
93 {
94 if (client->write_head(header) == false)
95 {
96 logger_error("write header error");
97 delete client;
98 return i;
99 }
100 if (client->read_head() == false)
101 {
102 logger_error("read header error");
103 delete client;
104 return i;
105 }
106
107 while (true)
108 {
109 int ret = client->read_body(buf, sizeof(buf) - 1);
110 if (ret < 0)
111 {
112 logger_error("read body error");
113 delete client;
114 return i;
115 }
116 else if (ret == 0)
117 break;
118 if (show_body_)
119 {
120 buf[ret] = 0;
121 printf("[%s]\r\n", buf);
122 fflush(stdout);
123 }
124 }
125
126 if (!keep_alive_)
127 {
128 delete client;
129 client = new acl::http_client;

Callers

nothing calls this directly

Calls 9

set_keep_aliveMethod · 0.80
accept_gzipMethod · 0.80
read_headMethod · 0.80
connect_serverFunction · 0.50
c_strMethod · 0.45
write_headMethod · 0.45
read_bodyMethod · 0.45
resetMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected