Send PUT request with PHP cURL

后端 未结 2 903
梦谈多话
梦谈多话 2020-12-12 02:10

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

相关标签:
2条回答
  • 2020-12-12 02:49
    1. HTTP PUT method is generally used to update resource.
    2. First need to bring (GET) resource information.
    3. and then update resource information according your parameters.
    4. Finally, make PUT request to server.

    In php, curl is used for making rest calls. HTTP GET and POST are directly supported in curl. But for PUT and DELETE you have to set options accordingly in curl_setopt()

         $curl = curl_init($url);
    
         **curl_setopt($curl,CURLOPT_CUSTOMREQUEST,"PUT")**;
         curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
    
         curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
    
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl,CURLOPT_POSTFIELDS,$update_para);
    
         $curl_response = curl_exec($curl);
    
    0 讨论(0)
  • 2020-12-12 02:53

    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?

    0 讨论(0)
提交回复
热议问题