c++ - libcurl curl_easy_setopt "Unknown error" -


i'm trying use c++ curl library sending json data via put method , code looks this

curl*    m_curlhandle; curlcode m_returnvalue;  //function1 start curl_global_init(curl_global_all);  struct curl_slist* headers = null; std::ostringstream oss; struct curl_slist* slist = null; slist = curl_slist_append(headers, "accept: application/json"); slist = curl_slist_append(headers, "content-type: application/json"); slist = curl_slist_append(headers, "charsets: utf-8");  m_curlhandle = curl_easy_init();  if (!m_curlhandle)     // throw exception  curl_easy_setopt(m_curlhandle, curlopt_httpheader, headers); //function1 end  //function2 start std::string url = "some url"; // url curl_easy_setopt(m_curlhandle, curlopt_url, url.c_str()); unsigned int timeout = 5; curl_easy_setopt(m_curlhandle, curlopt_timeout, timeout); std::string localip = "some ip"; // ip address curl_easy_setopt(m_curlhandle, curlopt_interface, localip.c_str()); curl_easy_setopt(m_curlhandle, curlopt_customrequest, "put"); std::string json = "some json struct"; //my json struct curl_easy_setopt(m_curlhandle, curlopt_postfields, json.c_str()); curl_easy_setopt(m_curlhandle, curlopt_writefunction, callbackwriter); //static size_t callbackwriter(char* buffer, size_t size, size_t nmemb, void* userp); m_returnvalue = curl_easy_perform(m_curlhandle); //function2 end 

i call function1 function2 , problem curl_easy_setopt calls error code 1685083487 , error description "unknown error". may cause such result , how fix this?

thank in advance!

i use curlopt_postfields instead, func

void poolstr(const std::vector<unsigned char> &data, const std::string &url) { curl_global_init(curl_global_default); mcurl = curl_easy_init(); if(mcurl)  {          curl_easy_setopt(mcurl, curlopt_url, url.c_str());         curl_easy_setopt(mcurl, curlopt_post, 1l);         curl_easy_setopt(mcurl, curlopt_postfieldsize, data.size());         curl_easy_setopt(mcurl, curlopt_postfields, &data[0]);         mchunk = curl_slist_append(mchunk, "content-type: application/binary");         mchunk = curl_slist_append(mchunk, "expect:");         curl_easy_setopt(mcurl, curlopt_httpheader, mchunk);          curlcode res = curl_easy_perform(mcurl);         if(res != curle_ok)         {             logerror << "curl_easy_perform() failed: " << curl_easy_strerror(res) << "\n attepmt number: " << attempt;         }         else         {             loginfo << "data being sent.";         }     } } } 

and calling poolstr(data, mhost);


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -