| 4 | #include "stdafx.h" |
| 5 | |
| 6 | static 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; |
no test coverage detected
searching dependent graphs…