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

Method http_request

lib_acl_cpp/samples/check_trigger/http_thread.cpp:96–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96bool http_thread::http_request(acl::socket_stream* conn, const char* host)
97{
98 acl::http_request req(conn);
99 acl::http_header& header = req.request_header();
100
101 // ���� HTTP ����ͷ
102 header.set_url(url_.c_str())
103 .set_keep_alive(false)
104 .set_host(host)
105 .set_method(acl::HTTP_METHOD_GET)
106 .set_content_type("text/plain")
107 .add_entry("Accept-Encoding", "plain")
108 .accept_gzip(true);
109
110 // ���� HTTP ����ͷ��ͬʱ��ȡ��Ӧͷ
111 if (req.request(NULL, 0) == false)
112 {
113 logger_error("send request to %s error %s",
114 conn->get_peer(true), acl::last_serror());
115 return false;
116 }
117
118 acl::http_client* client = req.get_client();
119 long long int content_length = client->body_length();
120
121#if 1
122 acl::string buf;
123 int ret, len;
124
125 // ��ʼ��������
126 while (true)
127 {
128 ret = req.read_body(buf, true, &len);
129 if (ret == 0)
130 break;
131 if (ret < 0)
132 {
133 logger_error("get body from %s error",
134 conn->get_peer(true));
135 return false;
136 }
137 length_ += len;
138 }
139#else
140 // sohu �� www.sohu.com �Ƚ�������Ȼ�ͻ��˷�����ֻ���� plain ����
141 // ����Ȼ�ᷢ gzip ��Ӧ����
142 char buf[8192];
143 int ret;
144
145 // ��ʼ��������
146 while (true)
147 {
148 ret = req.get_body(buf, sizeof(buf) - 1);
149 if (ret == 0)
150 break;
151 if (ret < 0)
152 {
153 logger_error("get body from %s error",

Callers

nothing calls this directly

Calls 12

request_headerMethod · 0.80
accept_gzipMethod · 0.80
set_content_typeMethod · 0.80
set_keep_aliveMethod · 0.80
last_serrorFunction · 0.50
c_strMethod · 0.45
requestMethod · 0.45
get_peerMethod · 0.45
get_clientMethod · 0.45
body_lengthMethod · 0.45
read_bodyMethod · 0.45
get_bodyMethod · 0.45

Tested by

no test coverage detected