Add option to disable SSL validate

dev v0.4
marcelb 1 year ago
parent 58fe5f1673
commit 16440a9c71
  1. 8
      lib/cppurl.hpp
  2. 8
      src/cppurl.cpp

@ -4,6 +4,7 @@
#include <curl/curl.h>
#include <string>
#include <map>
#include <iostream>
namespace marcelb {
@ -18,6 +19,7 @@ class Curl {
struct curl_slist *headers = NULL;
string _useragent;
long _timeout = 0;
bool _sslvalidate = true;
public:
@ -44,6 +46,12 @@ class Curl {
Curl& timeout(const long _timeout);
/**
* Omogući/onemogući validaciju certifikata kod SSL veza
*/
Curl& sslvalidate(const bool sslvalidate_);
/**
* Izvršiv HTTP GET zahtjev
* Vraća string HTTP tjela

@ -31,6 +31,10 @@ Curl& marcelb::Curl::timeout(const long timeout_) {
return *this;
}
Curl& marcelb::Curl::sslvalidate(const bool sslvalidate_) {
_sslvalidate = sslvalidate_;
return *this;
}
string marcelb::Curl::get(const string& req){
curl = curl_easy_init();
@ -48,6 +52,10 @@ string marcelb::Curl::get(const string& req){
if (_timeout > 0) {
curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS , _timeout);
}
if (!_sslvalidate) {
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, _sslvalidate ? 1 : 0);
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, _sslvalidate ? 1 : 0);
}
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);

Loading…
Cancel
Save