| 28 | } |
| 29 | |
| 30 | bool url_get() { |
| 31 | const char* addr = "www.baidu.com:80"; |
| 32 | acl::http_request req(addr, 5); |
| 33 | req.request_header().set_url("/") |
| 34 | .set_host("www.baidu.com"); |
| 35 | |
| 36 | if (!req.request(nullptr, 0)) { |
| 37 | log_info("%s: http request error, addr=%s", __func__, addr); |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | int http_status = req.http_status(); |
| 42 | acl::string buf; |
| 43 | buf.format("http status=%d", http_status); |
| 44 | log_info( "%s: url_get", __func__, buf.c_str()); |
| 45 | |
| 46 | if (!req.get_body(body_)) { |
| 47 | log_error("%s: get http body error!", __func__); |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | req.get_client()->sprint_header(head_); |
| 52 | log_info("%s: http response body: %s", __func__, body_.c_str()); |
| 53 | return true; |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | static napi_value HttpGet(napi_env env, napi_callback_info info) |
nothing calls this directly
no test coverage detected