Esempio n. 1
0
/**
 * Perform a HTTP request, return response object
 *
 * @since 1.7
 * @param string $type HTTP request type (GET, POST)
 * @param string $url URL to request
 * @param array $headers Extra headers to send with the request
 * @param array $data Data to send either as a query string for GET requests, or in the body for POST requests
 * @param array $options Options for the request (see /includes/Requests/Requests.php:request())
 * @return object Requests_Response object
 */
function yourls_http_request($type, $url, $headers, $data, $options)
{
    yourls_http_load_library();
    $options = array_merge(yourls_http_default_options(), $options);
    if (yourls_http_proxy_is_defined() && !yourls_send_through_proxy($url)) {
        unset($options['proxy']);
    }
    try {
        $result = Requests::request($url, $headers, $data, $type, $options);
    } catch (Requests_Exception $e) {
        $result = yourls_debug_log($e->getMessage() . ' (' . $type . ' on ' . $url . ')');
    }
    return $result;
}
Esempio n. 2
0
/**
 * Perform a HTTP request, return response object
 *
 * @since 1.7
 * @param string $type HTTP request type (GET, POST)
 * @param string $url URL to request
 * @param array $headers Extra headers to send with the request
 * @param array $data Data to send either as a query string for GET requests, or in the body for POST requests
 * @param array $options Options for the request (see /includes/Requests/Requests.php:request())
 * @return object Requests_Response object
 */
function yourls_http_request($type, $url, $headers, $data, $options)
{
    // Allow plugins to short-circuit the whole function
    $pre = yourls_apply_filter('shunt_yourls_http_request', null, $type, $url, $headers, $data, $options);
    if (null !== $pre) {
        return $pre;
    }
    yourls_http_load_library();
    $options = array_merge(yourls_http_default_options(), $options);
    if (yourls_http_get_proxy() && !yourls_send_through_proxy($url)) {
        unset($options['proxy']);
    }
    try {
        $result = Requests::request($url, $headers, $data, $type, $options);
    } catch (Requests_Exception $e) {
        $result = yourls_debug_log($e->getMessage() . ' (' . $type . ' on ' . $url . ')');
    }
    return $result;
}