Utsav Chatterjee
Utsav Chatterjee

Reputation: 41

How to set method of CURL to PUT?

I am trying to set the http method of Curl to PUT but my code is not working

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: 
  application/json','Content-Length: ' . strlen($post)));
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

The above code is what I have written but it is not setting it to PUT method Please help

Upvotes: 0

Views: 743

Answers (1)

Rakesh
Rakesh

Reputation: 82755

Try changing

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');

to

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');

Upvotes: 1

Related Questions