Difference between wp_remote_post and wp_safe_remote_post

[*] [**]The documentation for wp_remote_post says [**]In many cases you may be better served with wp_safe_remote_post [**]Looking at the source code, the only line that’s different between the two is that wp_safe_remote_post has this: $args[‘reject_unsafe_urls’] = true; [**]This article was the best explanation I found, which seems to indicate that the only time I should … Read more

Wp_remote_post not posting data

This works in php: $postdata = http_build_query( array( ‘api’ => get_option(‘API_key’), ‘gw’ => ‘1’ ) ); $opts = array(‘http’ => array( ‘method’ => ‘POST’, ‘header’ => ‘Content-type: application/x-www-form-urlencoded’, ‘content’ => $postdata ) ); $context = stream_context_create($opts); $api_response = file_get_contents(‘https://myurl.com/api’, false, $context); However, this does not work in WordPress: $args = array( ‘method’ => ‘POST’, ‘headers’ … Read more

Send data to 3rd party api with wp_remote_post on wp_login

Is it possible to use wp_remote_post to send http post requests to 3rd party api’s? I wasn’t able to successfully save the user object as a javascript variable, so I was hoping I could make an http request with php and handle the javascript manipulation in my node express app. Current attempt: function identify_user() { … Read more

Error timed out with succesfull wp_remote_post

What I’m trying to do: Passing POST data by using wp_remote_post. foreach ( $articles as $article_id ) { $postarray = array( ‘method’ => ‘POST’, ‘timeout’ => 5, ‘redirection’ => 5, ‘httpversion’ => ‘1.0’, ‘blocking’ => true, ‘headers’ => array(), ‘body’ => array( ‘article_id’ => $article_id ), ‘cookies’ => array() ); $response = wp_remote_post($url, $postarray); if … Read more

How to add Request header in WordPress remote api calls

Hey am new to WP development, can any one tell me how to add request headers in wp_remote_get() or wp_remote_post() remote api calls. I tried the following but didnt work $response = wp_remote_get( add_query_arg( array( ‘Affiliate-Id’ => XXXXX, ‘Affiliate-Token’ => XXXXX ), $api_url ) , array( ‘timeout’ => 10)); 1 1 If you want to … Read more

Sending JSON string through wp_remote_post()

I’m building a mailchimp integration and they require a POST call with JSON code. No, I’m using this code that actually works: $data = wp_remote_post($url, array( ‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’), ‘body’ => json_encode($array_with_parameters), ‘method’ => ‘POST’ )); But, it returns a PHP warning Warning: http_build_query(): Parameter 1 expected to be Array or Object. … Read more