2012-06-19 34 views
3

我想使用wp_remote_post從一臺服務器發送信息到我的其他網站。WordPress的wp_remote_post

所以基本上,我已經加入這一行我的代碼 -

$sidebarHTTP = site_url(); // Retrieves HTTP Url of sidebar 
$sidebarActivation = $sidebar.' , '.$sidebarHTTP; // Activate Sidebar 
$args = array(
    'method' => 'post', 
    'body' => array('sidebar' => $sidebar, 'sidebarHTTP' => $sidebarHTTP), 
    'user-agent' => 'My site' 
); 
wp_remote_post('http://mysite.com', $args); // Loads all default data 

因此,基本上,它不發送任何東西。是的,我輸入了正確的域名。也許它確實發送了一些東西,但我不知道如何從該網站獲取$ args ['body']。此外,我嘗試添加$ response = wp_remote_post ....然後發送郵件$ response ['body'],但它只是將主頁的源代碼發送到電子郵件。

希望能有所幫助。

+0

1,做u看到這個頁面:http://codex.wordpress.org/Function_API/wp_remote_post;第二,檢查捲曲是否打開? – Sergey

回答

2

您需要在php.ini文件中啓用cURL。

wp_remote_post()使用一種稱爲WP_Http類又可以使用三種交通工具類(參見文件class-http.php功能_get_first_available_transport)之一。

POST方法將與類WP_Http_Curl一起使用,但不會與類WP_Http_Streams(cURL回退)一起使用。

另一種方法是使用wp_remote_get()