Articles of wp remote post

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));

http_response_timeout filter not working

I am writing a WordPress plugin that makes calls to external sites. I want to raise the timeout for all wp_remote_* calls, so I added the following to the __construct function of my plugin: add_filter(“http_response_timeout”, function($timeout) { return 30; }); But the calls still time out after 5 seconds. I also tried using a separate […]

Change the headers content type with wp_remote_post

Working with the remote API requests with WordPress. I have used wp_remote_post() function to request the HTTP data but I am unable to update the headers Content-type I am using the following code wp_remote_post( $url, array( ‘method’ => ‘POST’, ‘timeout’ => 45, ‘redirection’ => 5, ‘httpversion’ => ‘1.0’, ‘blocking’ => true, ‘headers’ => array(“Content-type” => […]

How to send file by wp_remote_post?

I don’t want cURL in my WordPress plugin Hi, cURL is not safe to use on WordPress site. And sometime, cURL has been disable on customer hosting. And i decided to use wp_remote_post to send file for my plugin Here my code : $service = URL SERVICE ; $headers = array( ‘accept’ => ‘application/json’, // […]

creating form for wp_remote_post

i’m using code from the wordpress codex: (this is the generic version, my code is working though) $response = wp_remote_post( $url, array( ‘method’ => ‘POST’, ‘timeout’ => 45, ‘redirection’ => 5, ‘httpversion’ => ‘1.0’, ‘blocking’ => true, ‘headers’ => array(), ‘body’ => array( ‘name’ => ‘bob’, ’email’ => ‘bob@example.com’ ), ‘cookies’ => array() ) ); […]

On Plugin Activation, How Do I Check for Proper Transport Mechanism?

For a plugin that communicates with somewhere else, I hear we’re supposed to use wp_remote_post and wp_remote_get instead of PHP’s Curl library. Okay, but is there a fast and proper way on plugin execution to test for a blog’s PHP/host OS to have the proper transport mechanism installed? I mean, I could attempt a test […]

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 […]

Remote login with only the username not working

I’m writing a module for remote login into another WP site via my plugin’s admin. This is the code I’m using on the sender side: <?php add_action(‘init’, ‘connect’); function connect() { //I submit the username via a form in my plugin admin page if(isset($_POST[‘username’]) && $_POST[‘username’] != ”) { $name = $_POST[‘username’]; $response = wp_remote_post( […]

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. […]

How can I use CURLOPT_USERPWD in wp_remote_post?

I’m trying to setup a proper cURL call in WordPress so am using wp_remote_post(). However, I’m having trouble authenticating the user via wp_remote_post(). Any idea how to convert the following to be used in wp_remote_post? curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”); Full example of proper cURL basic auth is here.