Wordpress wp_remote_post [英] Wordpress wp_remote_post
问题描述
我想使用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'=>'我的网站'
);
wp_remote_post('http://mysite.com',$ args); //加载所有默认数据
基本上,它不会发送任何内容。是,我输入了正确的域名。也许它发送的东西,但我不知道如何从该网站检索$ args ['body']。此外,我尝试添加$ response = wp_remote_post ....然后发送邮件$ response ['body'],但它只是发送主页的源代码到电子邮件。
您需要在php.ini文件中启用cURL。
wp_remote_post()
使用一个名为 WP_Http
的类,传输类(见文件 class-http.php
function _get_first_available_transport
)。
POST方法将使用类 WP_Http_Curl
,但不能使用类 WP_Http_Streams
)。
另一种方法是使用 wp_remote_get()
I want to use wp_remote_post to send information from one server to my other website.
So basically, I have added this line to my code -
$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
So basically, it doesn't send anything. Yes, I have correct domain entered. Maybe it does send something, but I don't know how can I retrieve the $args['body'] from that site. Also, I tried adding $response = wp_remote_post.... and then sending mail $response['body'], but it just sends source code of homepage to email.
Would appreciate help.
You will need to enable cURL in your php.ini file.
wp_remote_post()
uses a class called WP_Http
that in turn can use one of three transport classes (see file class-http.php
function _get_first_available_transport
).
POST method will work with class WP_Http_Curl
, but will not work with class WP_Http_Streams
(the cURL fallback).
The alternative is to use wp_remote_get()
这篇关于Wordpress wp_remote_post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!