0

How do I send http Authorization header in http GET request in drupal ?

Every things else works except the authorization part.

My custom module code:

/*
 *Implements hook_menu
 */
function mymodule_menu() {

$items['demo'] = array(
    'title' => 'Demo API integration with Drupal 7',
    'page callback' => 'demo_page',
    'access callback' => TRUE,
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    );
return $items;
}

//page callback
function demo_page() {

$options = array(
  'method' => 'GET',
  'data' => '',
  'timeout' => 15,
  'headers' => array('Accept' => 'application/json',
                    'Authorization' => 'Basic SomeKey23412lkjdfadjfadfasd'),
);

$result = drupal_http_request('https://api.examlesite.com/test/', $options);
var_dump($result);
drupal_set_message("Result is processing");
return "hello world";
}
1

You can add basic authorization to url to access http basic protected address.

  // http auth
  $remote_url = 'http://uname:pw1234@example.com/service/node';
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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