C++ curl POST for LiFx Control -
i'm using curl c++ list bulbs
curl_easy_setopt(curl,curlopt_username, my_api_key); curl_easy_setopt(curl, curlopt_url, "https://api.lifx.com/v1beta1/lights/all/"); curl_easy_setopt(curl, curlopt_ssl_verifypeer, false); curl_easy_setopt(curl, curlopt_writefunction, writecallback); curl_easy_setopt(curl, curlopt_writedata, &data); res = curl_easy_perform(curl);
to toggle power light documentation http://developer.lifx.com/#toggle-power says use
curl -u "c87c73a896b554367fac61f71dd3656af8d93a525a4e87df5952c6078a89d192:" -x post "https://api.lifx.com/v1beta1/lights/all/toggle"
i've tested via pre-built curl binary works fine. can't figure out how construct post format in c++ code.
curl_easy_setopt(curl,curlopt_username, my_api_key); curl_easy_setopt(curl,curlopt_post,"https://api.lifx.com/v1beta1/lights/all/toggle"); curl_easy_setopt(curl,curlopt_ssl_verifypeer, false); curl_easy_setopt(curl,curlopt_writefunction, writecallback); curl_easy_setopt(curl,curlopt_writedata, &data); res = curl_easy_perform(curl);
however, res returns curle_url_malformat, think because haven't set curlopt_url property... i'm not sure needs set to.
i tried using similar format php question (php http curl put request lifx power on/off) no luck, still returns curle_url_malformat.
curlopt_post wrongly used there. should set 0 or 1 only. set url curlopt_url.
you use --libcurl sample.c
added (working) curl command line sample source code start from.
to mimic command line closer, can skip curlopt_post , have curlopt_customrequest set "post"
Comments
Post a Comment