wp_remote_get( $url, $args ) not working?


wp_remote_get( $url, $args ) not working?

我试图请求数据从处女给予api显示我的筹款信息在我的博客。我是一个完全的新手,在阅读和尝试了我能找到的关于这个主题的一切之后,我无法锻炼出如何完成这样的任务。这是我在cloud9上的wordpress安装中的.php文件中使用的代码(我已经删除了搜索和api密钥)。我还在我的实时博客上的一个页面上尝试了代码,该页面由Bluehost托管。我不确定我是否在正确的位置创建页面,或者下面的代码是否应该包装在某种函数中。如果您能提供任何帮助,我将不胜感激。

$url = "https://api.virginmoneygiving.com/fundraisers/v1/";
$args = array(
'headers' => array( "Content-type" => "application/json" ), 
'httpversion' => 1.1,
);
$response = wp_remote_get( $url, $args );
$body = wp_remote_retrieve_body( $response );
$response_code =  wp_remote_retrieve_response_code( $response );
print_r( $response_code  );
echo $response;

'httpversion'取字符串…

'httpversion' => '1.1',