[英]C++ curl POST for LiFx Control
I'm using curl with c++ to list all the bulbs successfully 我正在使用带有C ++的curl来成功列出所有灯泡
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 to all light the documentation http://developer.lifx.com/#toggle-power says to use 要完全切换电源, http : //developer.lifx.com/#toggle-power说明要使用的文档
curl -u "c87c73a896b554367fac61f71dd3656af8d93a525a4e87df5952c6078a89d192:" -X POST "https://api.lifx.com/v1beta1/lights/all/toggle"
I've tested this via the pre-built curl binary it works fine. 我已经通过预建的curl二进制文件对其进行了测试,效果很好。 I can't figure out how to construct the POST format in the C++ code.
我不知道如何在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);
However, res returns CURLE_URL_MALFORMAT, I think this is because I haven't set the CURLOPT_URL property... but I'm not sure what it needs to be set to. 但是,res返回CURLE_URL_MALFORMAT,我认为这是因为我尚未设置CURLOPT_URL属性...但是我不确定需要将其设置为什么。
I tried using a similar format to this PHP question ( PHP HTTP CURL PUT request for LIFX Power On/Off ) but with no luck, it still returns CURLE_URL_MALFORMAT. 我尝试使用与此PHP问题类似的格式( 用于LIFX Power On / Off的PHP HTTP CURL PUT请求 ),但是没有运气,它仍然返回CURLE_URL_MALFORMAT。
CURLOPT_POST is wrongly used there. 此处错误地使用了CURLOPT_POST 。 It should be set to 0 or 1 only.
仅应将其设置为0或1。 You set the URL with CURLOPT_URL .
您使用CURLOPT_URL设置URL。
You could use --libcurl sample.c
added to your (working) curl command line to get a good sample source code to start from. 您可以使用添加到您的(工作)curl命令行中的
--libcurl sample.c
来获取良好的示例源代码。
To mimic that command line closer, you can probably skip CURLOPT_POST and just have CURLOPT_CUSTOMREQUEST set to "POST" 为了更接近该命令行,您可以跳过CURLOPT_POST,而只需将CURLOPT_CUSTOMREQUEST设置为“ POST”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.