Send data to 3rd party api with wp_remote_post on wp_login

The ‘body’ needs to be an array, not including the ‘json_encode($user)’ piece. $response = wp_remote_post( ‘myapp.com/endpoint’, array( ‘method’ => ‘POST’, ‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’), ‘body’ => $user ) ); I have this in my function since I also had issues with the body being an object: if (is_object($user) && !is_array($user)) $user = json_decode(json_encode($user), … Read more

Error timed out with succesfull wp_remote_post

After quite some time letting the error message bugging my screen, I figured out a way to solve this. Yes, it’s a timeout issue, and the codex didn’t help me much. So I tried another approach, by setting a filter; add_filter( ‘http_request_timeout’, ‘wp9838c_timeout_extend’ ); function wp9838c_timeout_extend( $time ) { // Default timeout is 5 return … Read more

Sending JSON string through wp_remote_post()

Try setting the data_format parameter in your request like so: $data = wp_remote_post($url, array( ‘headers’ => array(‘Content-Type’ => ‘application/json; charset=utf-8’), ‘body’ => json_encode($array_with_parameters), ‘method’ => ‘POST’, ‘data_format’ => ‘body’, )); It looks like the format may be defaulting to query, in which case WordPress attempts to format the data using http_build_query, which is giving you … Read more