API getting null values with wp_remote_post

I’m trying to post some data to an API and I keep getting null values in the fields. My PHP code: $url=”https://apiconnector.com/v2/address-books/136517/contacts”; $username=”apiuser”; $password = ‘passwd’; $headers = array( ‘Authorization’ => ‘Basic ‘ . base64_encode( “$username:$password” ), ‘Content-Type’ => ‘application/json’ ); $fields = array( ‘body’ => json_encode( array( ‘EMAIL’ => ‘[email protected]’, ‘dataFields’ => array( ‘COUNTRY’ … Read more

How to set charset for wp_remote_post request?

I’m using wp_remote_post() on a project and it works great. But seems like the server on which I need to make the POST request is a Windows (ISS) server. So the third-party service that provides this specific endpoint requires that all POST requests has a Windows-1252 character encoding, otherwise there will be issues with special … Read more

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” => … Read more

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. 1 Answer 1 Use the … Read more