Curlopts


SUBMITTED BY: Guest

DATE: Dec. 3, 2013, 4:33 a.m.

FORMAT: C++

SIZE: 719 Bytes

HITS: 751

  1. size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp)
  2. {
  3. size_t realsize = size * nmemb;
  4. //stringLock.lock();
  5. ((string*)userp)->append((char*)contents, realsize);
  6. //stringLock.unlock();
  7. return realsize;
  8. }
  9. void getURL(string url, FetchResult* result)
  10. {
  11. CURL *curl;
  12. CURLcode res;
  13. string body;
  14. curl = curl_easy_init();
  15. if(curl)
  16. {
  17. curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  18. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
  19. curl_easy_setopt(curl, CURLOPT_WRITEDATA, &(result->value));
  20. res = curl_easy_perform(curl);
  21. /* always cleanup */
  22. curl_easy_cleanup(curl);
  23. }
  24. }

comments powered by Disqus