I have a rule set up that runs during cron. Part of that rule is an action that is supposed to save a PDF (via Entity Print which only authenticated users can access) to my server. It works fine when I manually execute it, but when I schedule it, and it gets executed via cron, I get an access denied error.
I have tried to Safely Impersonate Another User, and have also tried to send cookies with the request (based off the Rules download module), but continue to get access denied errors.
global $user;
$original_user = $user;
$old_state = drupal_save_session();
drupal_save_session(FALSE);
$user = user_load(1);
$headers = array();
if ($cookie) {
$headers = array(
'Cookie' => $_SERVER['HTTP_COOKIE'],
);
}
$response = drupal_http_request($url, array('headers' => $headers));
$user = $original_user;
drupal_save_session($old_state);
Is there a way to execute this drupal_http_request
as an authenticated user during cron?
drupal_http_request
with them.drupal_http_request()
, there isn't any difference between running it as anonymous user and authenticated user. If you are expecting the remote site to which the request is addressed to recognize the user as authenticated, you need to do more than passing a cookie to the server.