【发布时间】:2015-08-16 18:38:00
【问题描述】:
我正在使用 curl 和 c++ 成功列出所有灯泡
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);
文档http://developer.lifx.com/#toggle-power说要使用所有灯来切换电源
curl -u "c87c73a896b554367fac61f71dd3656af8d93a525a4e87df5952c6078a89d192:" -X POST "https://api.lifx.com/v1beta1/lights/all/toggle"
我已经通过预构建的 curl 二进制文件对此进行了测试,它运行良好。我不知道如何在 C++ 代码中构造 POST 格式。
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);
但是,res 返回 CURLE_URL_MALFORMAT,我认为这是因为我没有设置 CURLOPT_URL 属性...但我不确定它需要设置什么。
我尝试使用与此 PHP 问题 (PHP HTTP CURL PUT request for LIFX Power On/Off) 类似的格式,但没有成功,它仍然返回 CURLE_URL_MALFORMAT。
【问题讨论】: