title: how can i post JSON object through cURL in php
body: <p>How can I post JSON objects to a web service, through cURL in php?</p>
  
  <p>I have an array</p>
  
  <pre><code>$data = array('username'=&gt;'abc','password'=&gt;'pass');
  </code></pre>
  
  <p>The webservice which I want to call accepts JSON object, if I convert the $data to JSON with json_encode, its not working for me.</p>
  
  <pre><code>$data = json_encode($data);
  
  curl_setopt($ch, CURLOPT_POST      ,1);
  curl_setopt($ch, CURLOPT_POSTFIELDS    ,$data);
  </code></pre>
  
  <p>Am I doing something wrong? or I need any more parameters to set?</p>
  
  <p>Thanks for help in advance.</p>
  
  <p>Tanmay</p>