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

Method run

lib_acl_cpp/samples/http_request/main.cpp:24–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 ~http_request_test() {}
23
24 bool run(void)
25 {
26 acl::string body;
27
28 // �ӱ����ļ��м�����������
29 if (acl::ifstream::load(file_, &body) == false)
30 {
31 logger_error("load %s error", file_.c_str());
32 return false;
33 }
34
35 // ���� HTTP ����ͻ���
36 acl::http_request req(server_addr_);
37
38 // ���� HTTP ����ͷ�ֶ�
39
40 acl::string ctype("text/");
41 ctype << stype_ << "; charset=" << charset_;
42
43 acl::http_header& hdr = req.request_header(); // ����ͷ���������
44 hdr.set_url("/");
45 hdr.set_content_type(ctype);
46
47 // ���� HTTP ��������
48 if (req.request(body.c_str(), body.length()) == false)
49 {
50 logger_error("send http request to %s error",
51 server_addr_.c_str());
52 return false;
53 }
54
55 // ȡ�� HTTP ��Ӧͷ�������ֶ�
56 const char* p = req.header_value("Content-Type");
57 if (p == NULL || *p == 0)
58 {
59 logger_error("no Content-Type");
60 return false;
61 }
62
63 // ���� HTTP ��Ӧͷ����������
64 acl::http_ctype content_type;
65 content_type.parse(p);
66
67 // ��Ӧͷ�������͵�������
68 const char* stype = content_type.get_stype();
69
70 bool ret;
71 if (stype == NULL)
72 ret = do_plain(req);
73 else if (strcasecmp(stype, "xml") == 0)
74 ret = do_xml(req);
75 else if (strcasecmp(stype, "json") == 0)
76 ret = do_json(req);
77 else
78 ret = do_plain(req);
79 if (ret == true)
80 printf("read ok!\r\n");
81 return ret;

Callers 1

mainFunction · 0.45

Calls 8

request_headerMethod · 0.80
set_content_typeMethod · 0.80
c_strMethod · 0.45
requestMethod · 0.45
lengthMethod · 0.45
header_valueMethod · 0.45
parseMethod · 0.45
get_stypeMethod · 0.45

Tested by

no test coverage detected