title: How do I make a PATCH request in PHP using cURL?
body: <p>I have to make a PATCH request using PhP cURL. I couldn't find any documentation, so I tried the following but it isn't working.</p>
  
  <pre><code>$data = "{'field_name': 'field_value'}";
  $url = "http://webservice.url";
  $headers = array('X-HTTP-Method-Override: PATCH');
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  $response = curl_exec($curl);
  curl_close($curl);
  </code></pre>
  
  <p>Any idea why this isn't working? How can I fix it?</p>
  
  <p><strong>Edit:</strong>
  I am connecting to a RESTful web service. It returns HTTP/1.1 200 for successful requests. Unsuccessful requests return HTTP/1.1 403. I keep getting 403.</p>
  
  <p>I tried changing $data to:</p>
  
  <pre><code>$data = "data={'field_name': 'field_value'}";
  </code></pre>
  
  <p>It didn't change the outcome. </p>
  
  <p><strong>Edit2:</strong>
  The final working code.</p>
  
  <pre><code>$data = "{'field_name': 'field_value'}";
  $url = "http://webservice.url";
  $headers = array('Content-Type: application/json');
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  $response = curl_exec($curl);
  curl_close($curl);
  </code></pre>