drupal_http_request() with POST returns a 405 error I am trying to call an external API with a POST method which is working fine on Postman, but when trying to implement it in a custom module using drupal_http_request() I am getting a strange error.


  The requested resource does not support http method 'GET'.


This is the extracted cURL command from Postman: curl --location --max-time 2000 --request POST 'https://example.com/api' --header 'Authorization: [token]' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'subject=Lead XXX' --data-urlencode 'firstName=XXX' --data-urlencode 'lastName=XXX' --data-urlencode 'Email=test@test.test' --data-urlencode 'Mobile=XXX' --data-urlencode 'Interest=XXX ' --data-urlencode 'meetingdate=2020-04-20T13:00:00.000'.

This is the code I am using.

$url = 'https://example.com/api';
$data = [
    'subject' =&gt; 'XXX',
    'firstName' =&gt; 'XXX',
    'lastName' =&gt; 'XXX',
    'Email' =&gt; 'test@test.test',
    'Mobile' =&gt; 'XXXX',
    'Interest' =&gt; 'Testing',
    'meetingdate' =&gt; '2020-04-20T13:00:00.000',
];
$options = [
    'method' =&gt; 'POST',
    'headers' =&gt; array(
        'Content-Type' =&gt; 'application/x-www-form-urlencoded',
        'Authorization' =&gt; [token],
    ),
    'data' =&gt; json_encode($data),
];
$request = drupal_http_request($url, $data);


I have the feeling this must be easy, but I couldn't figure out what I'm doing wrong. I search the documentation, searched here with no luck.

Any hit will be appreciated.
In your post request you have specified 

'Content-Type' =&gt; 'application/x-www-form-urlencoded'


but your post data is in JSON format. 

Perhaps you need

'Content-Type' =&gt; 'application/json'


alternatively, pass the raw $data array as the post data for key=value&amp;key1=value2 form encoding. 

You also need to pass the function parameter $options instead of $data

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