Why does drupal_http_request return a 400? I am having issues sending a POST via my module.
In my browser's REST client I get a 200 with
POST https://mydomain.com 
username=myuser&amp;password=password1

So I know that the service is working fine.
I tried to replicate this call in my Drupal module with
$url = &quot;https://mydomain.com&quot;;
$data = array(
    'username' =&gt; 'myuser',
    'password' =&gt; 'password1',
);

$data = http_build_query($data, '', '&amp;');
$options = array(
  'method' =&gt; 'POST',
  'data' =&gt; $data
);

$response = drupal_http_request($url, $options);

The response I get is a 400. according to this I am not constructing the request correctly.
Question: How should I change my code in order to get a 200?
Note: I am using Drupal 7.
Thanks.
It's probably that you are missing the Content-Type header, as detailed here. For Drupal 7, this should look like this:

&lt;?php
$response = drupal_http_request(
 'http://www.example.com',
 array('headers' =&gt; array('Content-Type' =&gt; 'application/x-www-form-urlencoded'),
 'method' =&gt; 'POST',
 'data' =&gt; 'param1=value1&amp;param2=value2'));
?&gt;