Add option to disable SSL validate
This commit is contained in:
parent
58fe5f1673
commit
16440a9c71
@ -4,6 +4,7 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace marcelb {
|
namespace marcelb {
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ class Curl {
|
|||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
string _useragent;
|
string _useragent;
|
||||||
long _timeout = 0;
|
long _timeout = 0;
|
||||||
|
bool _sslvalidate = true;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -44,6 +46,12 @@ class Curl {
|
|||||||
|
|
||||||
Curl& timeout(const long _timeout);
|
Curl& timeout(const long _timeout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Omogući/onemogući validaciju certifikata kod SSL veza
|
||||||
|
*/
|
||||||
|
|
||||||
|
Curl& sslvalidate(const bool sslvalidate_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Izvršiv HTTP GET zahtjev
|
* Izvršiv HTTP GET zahtjev
|
||||||
* Vraća string HTTP tjela
|
* Vraća string HTTP tjela
|
||||||
|
@ -31,6 +31,10 @@ Curl& marcelb::Curl::timeout(const long timeout_) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Curl& marcelb::Curl::sslvalidate(const bool sslvalidate_) {
|
||||||
|
_sslvalidate = sslvalidate_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
string marcelb::Curl::get(const string& req){
|
string marcelb::Curl::get(const string& req){
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
@ -48,6 +52,10 @@ string marcelb::Curl::get(const string& req){
|
|||||||
if (_timeout > 0) {
|
if (_timeout > 0) {
|
||||||
curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS , _timeout);
|
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_WRITEFUNCTION, WriteCallback);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||||
res = curl_easy_perform(curl);
|
res = curl_easy_perform(curl);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user