| 16 | ~http_request_test() {} |
| 17 | |
| 18 | bool run(const std::vector<std::string>& files, |
| 19 | const std::map<std::string, std::string>& params) { |
| 20 | const char* boundary = "----------------xxxxxx113333333"; |
| 21 | acl::http_mime mime(boundary); |
| 22 | |
| 23 | // ���Ӳ������� |
| 24 | for (std::map<std::string, std::string>::const_iterator cit = |
| 25 | params.begin(); cit != params.end(); ++cit) { |
| 26 | mime.add_param(cit->first.c_str(), cit->second.c_str()); |
| 27 | } |
| 28 | |
| 29 | int i = 0; |
| 30 | acl::string name; |
| 31 | // �����ļ���Ϣ |
| 32 | for (std::vector<std::string>::const_iterator cit = |
| 33 | files.begin(); cit != files.end(); ++cit) { |
| 34 | name.format("file-%d", i++); |
| 35 | mime.add_file(name.c_str(), cit->c_str()); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | // ���� HTTP ����ͻ��� |
| 40 | acl::http_request req(server_addr_); |
| 41 | |
| 42 | // ���� HTTP ����ͷ�ֶ� |
| 43 | acl::http_header& hdr = req.request_header(); // ����ͷ��������� |
| 44 | hdr.set_url("/upload"); |
| 45 | |
| 46 | #if 0 |
| 47 | // �����͵����ݱȽϴ�ʱ�����Բ��ô˷���������������ʱ���� |
| 48 | // �����ļ��У�Ȼ���ٷ��� |
| 49 | // ���� HTTP MIME �������� |
| 50 | const char* tmpfile = "./local.file"; |
| 51 | if (req.upload(mime, tmpfile, debug_mode_) == false) { |
| 52 | printf("upload to %s error\r\n", server_addr_.c_str()); |
| 53 | return false; |
| 54 | } |
| 55 | #else |
| 56 | // �������������Ƚ�Сʱ�����Բ��ô˷����������ݷ����ڴ��з��� |
| 57 | acl::string buff; |
| 58 | // ���� HTTP MIME �������� |
| 59 | if (req.upload(mime, debug_mode_ ? &buff : NULL) == false) { |
| 60 | printf("upload to %s error\r\n", server_addr_.c_str()); |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | if (debug_mode_) { |
| 65 | printf("buff:\r\n%s\r\n", buff.c_str()); |
| 66 | } |
| 67 | #endif |
| 68 | |
| 69 | acl::string body; |
| 70 | if (req.get_body(body) == false) { |
| 71 | printf("get http body error\r\n"); |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | printf("http status: %d\r\n", req.http_status()); |
no test coverage detected