如何将命令行cUrl转换为PHP cUrl

时间:2013-12-01 22:40:34

标签: php curl

我试图从PHP发布消息,我需要将以下命令转换为PHP cURL:

  curl -X PUT --data-binary "Hello World" http://eclipse.mqttbridge.com/test

无论我尝试什么,我都无法得到它。我尝试了curl_execexec命令但没有结果。如何将此命令转换为PHP cUrl,或者至少从exec命令执行?

谢谢!

1 个答案:

答案 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);