我试图从PHP发布消息,我需要将以下命令转换为PHP cURL:
curl -X PUT --data-binary "Hello World" http://eclipse.mqttbridge.com/test
无论我尝试什么,我都无法得到它。我尝试了curl_exec
和exec
命令但没有结果。如何将此命令转换为PHP cUrl,或者至少从exec
命令执行?
谢谢!
答案 0 :(得分:2)
$data = "Hello World";
$ch = curl_init('http://eclipse.mqttbridge.com/test');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);