WINDOWS C++ LibCURL 存取不要HTTPS認證的API
WINDOWS C++ LibCURL 存取不要HTTPS認證的API
GITHUB:https://github.com/jash-git/CPP_CURL_HTTPS
01.下載已經編譯好的CURL
7.59
02.下載對應的include/LIB
7.65.3
03.下載相關的DLL
程式碼:
#include <iostream> #include <cstdio> #include "include\curl\curl.h" #include "include\curl\easy.h" using namespace std; void pause() { printf("Press Enter key to continue…"); fgetc(stdin); } int main() { CURL *curl; CURLcode res; struct curl_slist *headerlist = NULL; static const char buf[] = "application/json; charset=UTF-8"; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { headerlist = curl_slist_append(headerlist, buf); //curl_easy_setopt(curl, CURLOPT_URL, "https://www.mof.gov.tw"); curl_easy_setopt(curl, CURLOPT_URL, "https://192.168.1.194:24408/syris/device/topology"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1_2);// | CURL_SSLVERSION_SSLv3 | CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_TLSv1_2 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);//SKIP_PEER_VERIFICATION curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);//SKIP_HOSTNAME_VERFICATION curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_POST, 0); // get reqest curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 0); curl_easy_setopt(curl, CURLOPT_READFUNCTION,NULL); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,NULL); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3); res = curl_easy_perform(curl); if(res !=CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); } curl_easy_cleanup(curl); curl_slist_free_all(headerlist); } pause(); return 0; }
程式執行結果:
One thought on “WINDOWS C++ LibCURL 存取不要HTTPS認證的API”
早上我司的大陸協力廠商,要使用純C++開發存取HTTPS的WEB API ,但是因為不會找對應的LIBCURL,一直來煩我司的FAE
搞到我最後還要寫出純C++的PROJECT 來堵他們的嘴
天啊 想不到自稱會寫C++的人還找不到對CURL LIB 實在有夠蝦
花了我一整天(畢竟我已經很少使用純C++開發了),趕快紀錄+PO出來 有需要請自取