I have major problem while getting response. I am using drupal_http_request to get the response but I get 400 as response though url given is working... I tried Curl Http Request module to overrride drupal_http_request. If i do that, then I get response code as 47 and error is maximum redirect followed. If I dont use CHR module, then error is 400 but through fiddler, or by POSTMAN, response is 200Ok.. Any help on this?

Below is my code

$url = "https://lastpass.com/misc_download2.php";
$options = array(
  'max_redirects' => 20,
  'headers' => array(
  'Content-Type' => 'application/x-www-form-urlencoded',
  'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36   (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36',
$check_url = drupal_http_request($url, $options);

print_r($check_url) is giving code=400

  • 400 is clearly a Bad Request error. You are setting application/x-www-form-urlencoded but you aren't sending any data.
    – apaderno
    Nov 30, 2015 at 6:51

1 Answer 1


drupal_http_request() has GET as a default method, you are requesting a resource with application/x-www-form-urlencoded which is only available on POST requests as far as I know. a fix can be as simple as:

$check_url = drupal_http_request($url, $options, 'POST');

Source: https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_http_request/4.6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.