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 calledWP_Http
that in turn can use one of three transport classes (see fileclass-http.php
function_get_first_available_transport
).POST method will work with class
WP_Http_Curl
, but will not work with classWP_Http_Streams
(the cURL fallback).The alternative is to use
wp_remote_get()