drupal_http_request() returns "Invalid JSON primitive" I am developing a module for Drupal 7 which calls a remote API. I am using drupal_http_build_query(), drupal_http_request(), and drupal_json_decode().
My code is as follows
$username = $form_state['input']['name'];
$password = $form_state['input']['pass'];

$authurl = variable_get('sgauth_base_url_authenticate', '');
$headers = array('Content-Type' =&gt; 'application/json');
$data = array('email' =&gt; $username, 'password' =&gt; $password);
$query = drupal_http_build_query($data);
$options = array('headers' =&gt; $headers, 'method' =&gt; 'POST', 'data' =&gt; $query);
$result = drupal_http_request($authurl, $options);

dpm($result);

$authurl is returning the correct url for the API.
When I look at the returned object I see the following
The request is (Note host, username and password have been hidden)
POST /SingPostApi/MobileAuthenticate HTTP/1.0 
Content-Type: application/json 
User-Agent: Drupal (+http://drupal.org/) 
Host: xxxxxxxxxxxx.xxxxxxxxxx.com 
Content-Length: 36

email=xxx%40xx.xxx&amp;password=xxxxxxxx

Which seems OK
$result-&gt;code I see a 500 error
$result-&gt;data shows Invalid JSON primitive: email.
As far as I can tell my code is OK based on my reading of the Drupal API. I don't understand why I am getting the wrong data returned.
When I make he POST request from the Firefox HTTP Requester I get a 200 code and the data I expect to see returned
I would appreciate it if someone who can see where I am going wrong can point me in the right direction.
If your request URL accepts only JSON object data, then you need to pass the value as JSON object, 
To convert the PHP array/object to JSON object use

drupal_json_encode($input);


If your request URL's output in the form of JSON object, you need to print the array/value after conveting into a JSON object and you need to add the header as 'application/json'

header('Content-Type: application/json');
echo drupal_json_decode($output);