2017-01-30 96 views
0

我发送简单的请求与wp_remote_post每次它返回一个空数组。WordPress wp_remote_post()返回空数组

我的代码

$url   = 'https://example.com/page.php'; 
$email   = get_option('admin_email'); 
$fields = array(
    'email'    => $email, 
    'site'    => get_site_url(), 
    ); 
$response = wp_remote_post($url, array(
    'method'  => 'POST', 
    'timeout'  => 5, 
    'httpversion' => '1.0', 
    'blocking' => false, 
    'headers'  => array(), 
    'body'  => $fields, 
    ) 
); 


if (is_wp_error($response)) { 
    $error_message = $response->get_error_message(); 
    echo "Something went wrong: $error_message"; 
} else { 
    echo 'Response:<pre>'; 
    print_r($response); 
    echo '</pre>'; 
} 

,我得到的回应是:

Array 
(
    [headers] => Array 
     (
     ) 

    [body] => 
    [response] => Array 
     (
      [code] => 
      [message] => 
     ) 

    [cookies] => Array 
     (
     ) 

    [http_response] => 
) 

回答

0

尝试删除 '堵' 参数。另外,您可能想要使用wp_safe_remote_post。

​​

+0

It works,Thanks :) –