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

Function test2

lib_acl_cpp/samples/ssl/ssl_client/ssl_client.cpp:126–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124}
125
126static void test2(const char* domain, int port, bool use_gzip, bool use_ssl)
127{
128 // ���� WEB ����������
129
130 acl::string addr;
131 addr << domain << ':' << port;
132
133 acl::http_client client;
134 if (!client.open(addr.c_str(), 60, 60, use_gzip)) {
135 std::cout << "connect " << addr.c_str()
136 << " error!" << std::endl;
137 return;
138 }
139
140 if (use_ssl) {
141 // ���� SSL ����������ͻ����������󶨣����������ͷ�ǰ�� SSL ����
142 // �����������ڲ�ͨ������ stream_hook::destroy() �ͷ�
143 acl::polarssl_io* ssl = new acl::polarssl_io(*__ssl_conf, false);
144 if (client.get_stream().setup_hook(ssl) == ssl) {
145 std::cout << "open ssl client " << addr.c_str()
146 << " error!" << std::endl;
147 ssl->destroy();
148 return;
149 }
150 }
151
152 // ���� HTTP ����ͷ
153
154 acl::http_header header;
155 header.set_url("/")
156 .set_host(domain)
157 .accept_gzip(use_gzip)
158 .add_entry("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0")
159 .add_entry("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
160 .add_entry("Accept-Languge", "zh-cn,en;q=0.5")
161 .add_entry("Pragma", "no-cache")
162 .add_entry("Cache-Control", "no-cache");
163
164 acl::string request;
165 header.build_request(request);
166
167 std::cout << "request:" << std::endl;
168 std::cout << "----------------------------------------" << std::endl;
169 std::cout << request.c_str();
170 std::cout << "----------------------------------------" << std::endl;
171
172 // ���� HTTP GET ����ͷ
173
174 if (!client.write_head(header)) {
175 std::cout << "write to " << addr.c_str()
176 << " error!" << std::endl;
177 return;
178 }
179
180 // ��ȡ HTTP ��Ӧͷ
181 if (!client.read_head()) {
182 std::cout << "read http respond header error!" << std::endl;
183 return;

Callers 1

mainFunction · 0.70

Calls 11

accept_gzipMethod · 0.80
read_headMethod · 0.80
get_respond_headMethod · 0.80
openMethod · 0.45
c_strMethod · 0.45
setup_hookMethod · 0.45
get_streamMethod · 0.45
destroyMethod · 0.45
build_requestMethod · 0.45
write_headMethod · 0.45
read_bodyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…