GC_Http::_dispatch_request()
最后更新于:2021-12-01 11:13:29
GC_( string$url, array$args)Dispatches a HTTP request to a supporting transport.
参数
- $url
-
(string) (Required) URL to request.
- $args
-
(array) (Required) Request arguments.
响应
(array|GC_Error) Array containing ‘headers’, ‘body’, ‘response’, ‘cookies’, ‘filename’. A GC_Error instance upon error.
源文件
文件: gc-includes/class-http.php
private function _dispatch_request( $url, $args ) {
static $transports = array();
$class = $this->_get_first_available_transport( $args, $url );
if ( ! $class ) {
return new GC_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) );
}
// Transport claims to support request, instantiate it and give it a whirl.
if ( empty( $transports[ $class ] ) ) {
$transports[ $class ] = new $class;
}
$response = $transports[ $class ]->request( $url, $args );
/** This action is documented in gc-includes/class-http.php */
do_action( 'http_api_debug', $response, 'response', $class, $args, $url );
if ( is_gc_error( $response ) ) {
return $response;
}
/** This filter is documented in gc-includes/class-http.php */
return apply_filters( 'http_response', $response, $args, $url );
}