WordPress wp_remote_post

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 –

Read More
$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.

Related posts

Leave a Reply

1 comment

  1. 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()