且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PHP cURL发送PUT请求

更新时间:2022-10-18 17:52:28

CURLOPT_PUT,true);



有关更多信息,您可以参考:如何在PHP中启动GET / POST / PUT / DELETE请求和判断请求类型?


I'm trying to communicate with a web service who's waiting first a token in each request. There is my problem, the web service is waiting the token throught file_get_contenst(php://input).

I didn't find a way to send cURL request trought this method (sending raw data/put data instead of Post). Could some one guides me ?

I tried something like :

$fp = fopen('php://temp/maxmemory:256000', 'w');
fwrite($fp, TOKEN);
fseek($fp, 0);
curl_setopt($ch, CURLOPT_INFILE, $fp); // file pointer
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($json));

curl_setopt($ch, CURLOPT_PUT, true);

For more info you can refer: How to start a GET/POST/PUT/DELETE request and judge request type in PHP?