Browse Source

#IQRV #comment [Merge] 探测库同步

gifur 2 years ago
parent
commit
662768e17c
1 changed files with 4 additions and 8 deletions
  1. 4 8
      Other/libRestfulFunc/HttpProbeImpl.cpp

+ 4 - 8
Other/libRestfulFunc/HttpProbeImpl.cpp

@@ -27,28 +27,25 @@ int HttpProbe(const std::string& url, std::string& out_msg, uint32_t wait_max_se
         const pplx::task<void> request_task = pplx::task<http_response>([&]() {
 
             http_client_config config;
-
             if (wait_max_secs != (uint32_t)(-1)) {
                 config.set_timeout(utility::seconds(wait_max_secs));
             }
-
             config.set_validate_certificates(false);
 
+            http_request request_content(methods::GET);
+            request_content.headers().add(U("User-Agent"), U("httpclientcpp-agent/1.0"));
+
             http_client client(url, config);
-            return client.request(methods::GET);
+            return client.request(request_content);
                                                                         }).then([&](http_response response) {
                                                                             ucout << U(">>>>>> response status: ") << response.status_code() << std::endl;
                                                                             result = response.status_code();
                                                                                 });
                                                                         try {
-
                                                                             request_task.wait();
-
                                                                         } catch (const std::exception& e) {
-
                                                                             out_msg = e.what();
                                                                             std::cout << "exception occurs: " << e.what() << "\n\n";
-
                                                                             if (strstr(e.what(), "12002") != nullptr || strstr(e.what(), "Request canceled by user") != nullptr) {
                                                                                 result = -2;
                                                                             } else if (strstr(e.what(), "URI must contain a hostname") != nullptr) {
@@ -58,6 +55,5 @@ int HttpProbe(const std::string& url, std::string& out_msg, uint32_t wait_max_se
                                                                             }
                                                                         }
     }
-
     return result;
 }