From dcf88b9538bb44308cd9c9630099f29de3847e28 Mon Sep 17 00:00:00 2001 From: hhchinasoft Date: Mon, 6 Dec 2021 15:56:33 +0800 Subject: [PATCH] http code check clean Signed-off-by: hhchinasoft --- frameworks/js/napi/http/src/http_request.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/frameworks/js/napi/http/src/http_request.cpp b/frameworks/js/napi/http/src/http_request.cpp index e0392cb80..a551e328d 100644 --- a/frameworks/js/napi/http/src/http_request.cpp +++ b/frameworks/js/napi/http/src/http_request.cpp @@ -165,8 +165,18 @@ bool HttpRequest::SetOptionForPost(CURL *curl, HttpRequestOptionsContext *asyncC NETMGR_LOGE("The parameter of curl or asyncContext is nullptr"); return false; } - curl_easy_setopt(curl, CURLOPT_URL, asyncContext->GetUrl().c_str()); - curl_easy_setopt(curl, CURLOPT_POST, 1L); + + CURLcode result = curl_easy_setopt(curl, CURLOPT_URL, asyncContext->GetUrl().c_str()); + if (result != CURLE_OK) { + NETMGR_LOGE("curl set option failed! error code %{public}d", result); + return false; + } + + result = curl_easy_setopt(curl, CURLOPT_POST, 1L); + if (result != CURLE_OK) { + NETMGR_LOGE("curl set option failed! error code %{public}d", result); + return false; + } return true; } @@ -195,7 +205,11 @@ bool HttpRequest::SetOptionForGet(CURL *curl, HttpRequestOptionsContext *asyncCo curl_free(encodeOut); } } - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + CURLcode result = curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + if (result != CURLE_OK) { + NETMGR_LOGE("curl set option failed! error code %{public}d", result); + return false; + } } else { std::size_t index = url.find(URL_SEPARATOR); if (index != std::string::npos) { -- Gitee