Curl和PHP-如何通过PUT,POST,GET通过curl传递json

Curl和PHP-如何通过PUT,POST,GET通过curl传递json,第1张

Curl和PHP-如何通过PUT,POST,GET通过curl传递json

$data = array('username'=>'dog','password'=>'tall');$data_json = json_enpre($data);$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$response  = curl_exec($ch);curl_close($ch);

开机自检

$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$response  = curl_exec($ch);curl_close($ch);

GET 参见@Dan H答案

删除

$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$response  = curl_exec($ch);curl_close($ch);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5114652.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-17
下一篇 2022-11-17

发表评论

登录后才能评论

评论列表(0条)

保存