How to convert a command line cUrl to PHP cUrl

匿名 (未验证) 提交于 2019-12-03 02:42:02

问题:

I was trying to publish messages from PHP and I need to convert the following command into a PHP cURL:

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

No matter what I try i cannot get it going. I tried curl_exec and exec commands but no results. How do you convert this command into PHP cUrl, or at least execute from exec command?

Thanks!

回答1:

    $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); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!