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

Function get_url

lib_acl_cpp/samples/http_client2/http_client2.cpp:6–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "stdafx.h"
5
6static void get_url(const char* url, const char* host,
7 const char* addr, const char* tofile)
8{
9 acl::http_header header;
10
11 //header.add_param("test", NULL);
12 header.set_method(acl::HTTP_METHOD_GET);
13 header.set_url(url);
14 header.set_content_type("text/xml; charset=utf-8");
15 if (header.get_host() == NULL)
16 {
17 header.set_host(host);
18 printf(">>>set host: %s\r\n", host);
19 }
20 else
21 printf(">>>host: %s\r\n", header.get_host());
22 header.set_keep_alive(true);
23 header.add_entry("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
24 header.add_entry("Accept", "*/*");
25 header.add_entry("Cache-Control", "no-cache");
26 header.accept_gzip(true);
27
28 acl::string buf;
29
30 header.build_request(buf);
31 printf("--------------------request------------------\r\n");
32 printf("%s\r\n", buf.c_str());
33
34 acl::http_client client;
35 printf("begin connect %s\r\n", addr);
36 if (client.open(addr, 10, 10) == false)
37 {
38 printf("open %s error\r\n", addr);
39 return;
40 }
41
42 if (client.write_head(header) == false)
43 {
44 printf("write request header error\r\n");
45 return;
46 }
47 if (client.read_head() == false)
48 {
49 printf("read response header error\r\n");
50 return;
51 }
52
53 client.print_header("response header");
54
55 acl::ofstream fp;
56 fp.open_write(tofile);
57 while (true)
58 {
59 int ret = client.read_body(buf);
60 if (ret < 0)
61 {
62 printf("connect closed now\r\n");
63 break;

Callers 1

mainFunction · 0.70

Calls 12

set_content_typeMethod · 0.80
set_keep_aliveMethod · 0.80
accept_gzipMethod · 0.80
read_headMethod · 0.80
print_headerMethod · 0.80
build_requestMethod · 0.45
c_strMethod · 0.45
openMethod · 0.45
write_headMethod · 0.45
open_writeMethod · 0.45
read_bodyMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…