简体   繁体   中英

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 -

$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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM