Advertisement
GoodTekken

20231101_http

Nov 1st, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <curl/curl.h>
  3.  
  4. size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp)
  5. {
  6. size_t totalSize = size * nmemb;
  7. reinterpret_cast<std::string*>(userp)->append(reinterpret_cast<char*>(contents), totalSize);
  8. return totalSize;
  9. }
  10.  
  11. int main()
  12. {
  13. CURL *curl = curl_easy_init();
  14. if(curl) {
  15. std::string readBuffer;
  16.  
  17. curl_easy_setopt(curl, CURLOPT_URL, "https://192.168.100.100/application-files/JTDemo.wef.gz");
  18. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
  19. curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
  20. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); // Skip SSL verification, not recommended in production
  21. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); // Skip SSL verification, not recommended in production
  22. CURLcode res = curl_easy_perform(curl);
  23.  
  24. if(res != CURLE_OK) {
  25. fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
  26. }
  27. else {
  28. std::ofstream outFile("JTDemo.wef.gz", std::ios::binary);
  29. outFile << readBuffer;
  30. }
  31.  
  32. curl_easy_cleanup(curl);
  33. }
  34.  
  35. return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement