8000 Merge pull request #474 from Brisdo/master · lebinlv/esp32-snippets@d38b15e · GitHub
[go: up one dir, main page]

Skip to content

Commit d38b15e

Browse files
authored
Merge pull request nkolban#474 from Brisdo/master
Added (long)response_code return values to get and post methods
2 parents eb25dac + a60e6de commit d38b15e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cpp_utils/RESTClient.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ RESTClient::~RESTClient() {
3636
/**
3737
* @brief Perform an HTTP GET request.
3838
*/
39-
void RESTClient::get() {
39+
long RESTClient::get() {
40+
long response_code; // Added return response_code 2018_4_12
4041
prepForCall();
4142
::curl_easy_setopt(m_curlHandle, CURLOPT_HTTPGET, 1);
4243
int rc = ::curl_easy_perform(m_curlHandle);
4344
if (rc != CURLE_OK) {
4445
ESP_LOGE(tag, "get(): %s", getErrorMessage().c_str());
4546
}
47+
curl_easy_getinfo(m_curlHandle, CURLINFO_RESPONSE_CODE, &response_code); // Added return response_code 2018_4_12
48+
return response_code; // Added return response_code 2018_4_12
4649
} // get
4750

4851

@@ -52,13 +55,16 @@ void RESTClient::get() {
5255
* @param [in] body The body of the payload to send with the post request.
5356
*
5457
*/
55-
void RESTClient::post(std::string body) {
58+
long RESTClient::post(std::string body) {
59+
long response_code; // Added return response_code 2018_4_12
5660
prepForCall();
5761
::curl_easy_setopt(m_curlHandle, CURLOPT_POSTFIELDS, body.c_str());
5862
int rc = ::curl_easy_perform(m_curlHandle);
5963
if (rc != CURLE_OK) {
6064
ESP_LOGE(tag, "post(): %s", getErrorMessage().c_str());
6165
}
66+
curl_easy_getinfo(m_curlHandle, CURLINFO_RESPONSE_CODE, &response_code);// Added return response_code 2018_4_12
67+
return response_code;// Added return response_code 2018_4_12
6268
} // post
6369

6470

cpp_utils/RESTClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class RESTClient {
6868
RESTClient();
6969
virtual ~RESTClient();
7070
void addHeader(std::string name, std::string value);
71-
void get();
71+
long get(); // Added return response_code 2018_4_12
7272
std::string getErrorMessage();
7373
/**
7474
* @brief Get the response payload data from the last REST call.
@@ -86,7 +86,7 @@ class RESTClient {
8686
return m_timings;
8787
}
8888

89-
void post(std::string body);
89+
long post(std::string body); // Added return response_code 2018_4_12
9090

9191
/**
9292
* @brief Set the URL for the target.

0 commit comments

Comments
 (0)
0