WordPress函数:wp_remote_fopen 用于获取内容的URI的HTTP请求

江河/ 2023年10月15日/ WordPress/ 浏览 515

函数原型:


wp_remote_fopen( string $uri ): string|false


用于获取内容的URI的HTTP请求。


函数源码:


function wp_remote_fopen( $uri ) {
	$parsed_url = parse_url( $uri );

	if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
		return false;
	}

	$options            = array();
	$options['timeout'] = 10;

	$response = wp_safe_remote_get( $uri, $options );

	if ( is_wp_error( $response ) ) {
		return false;
	}

	return wp_remote_retrieve_body( $response );
}


使用举例:


echo wp_remote_fopen( 'https://www.zhuige.com/' );


发表评论

暂无评论,抢个沙发...

客服 工单