function rules_http_client_request_url in Rules HTTP Client 7
Callback for 'request_url' rules action.
1 string reference to 'rules_http_client_request_url'
- rules_http_client_rules_action_info in ./
rules_http_client.rules.inc - Implements hook_rules_action_info().
File
- ./
rules_http_client.rules.inc, line 86 - Rules module integration.
Code
function rules_http_client_request_url($url, $headers = '', $method = 'GET', $data = NULL, $max_redirects = 3, $timeout = 30) {
// Headers.
$headers = explode("\r\n", $headers);
if (is_array($headers)) {
foreach ($headers as $header) {
if (!empty($header) && strpos($header, ':') !== FALSE) {
list($name, $value) = explode(':', $header, 2);
if (!empty($name)) {
$options['headers'][$name] = ltrim($value);
}
}
}
}
// Method.
$options['method'] = strtoupper($method);
// Data.
$options['data'] = drupal_http_build_query(drupal_parse_info_format($data));
// Max redirects.
$options['max_redirects'] = empty($max_redirects) ? 3 : $max_redirects;
// Timeout.
$options['timeout'] = empty($timeout) ? 30 : $timeout;
// Allow modules to alter the URL and options.
drupal_alter('rules_http_client_request', $url, $options);
$response = drupal_http_request($url, $options);
if (isset($response->error)) {
return;
}
else {
return array(
'http_response' => $response->data,
);
}
}