Post body not working with wp_remote_post()

You’re setting the Content-Type header to application/json and wp_remote_post() doesn’t intelligently JSON-encode the request data (the body array), so you should manually do it. So for example: ‘body’ => json_encode( array( ‘Username’ => ‘myusername’, ‘Password’ => ‘mypassword’ ) )

WordPress wp_remote_post vs wp_remote_request

You should be able to use both wp_remote_request() and wp_remote_post() for a ‘POST’ request, as they are just wrappers for the same WP_Http::request method that supports the methods: ‘GET’, ‘POST’, ‘HEAD’, ‘PUT’, ‘DELETE’, ‘TRACE’, ‘OPTIONS’, ‘PATCH’. and the default one is ‘GET’. The difference is that wp_remote_post() function has the ‘POST’ method explicitly set via … Read more

How to set charset for wp_remote_post request?

After trying several times to set the proper charset, I wasn’t successful. Then I searched for an workaround and found one that worked with my problem. In addition to set the charset like I mentioned above, what I did is to convert all strings on my POST body with this php snippet: $message = @iconv(“UTF-8″,”Windows-1252//IGNORE”,$message); … Read more

Stuck with wp_remote_post sending data to an external api on user registration

I recommend only setting the arguments you absolutely need to change from defaults, to eliminate potential issues while testing. It’s best to only add additional arguments as they are needed. All arguments can be found here: https://developer.wordpress.org/reference/classes/WP_Http/request/ If possible also remove the required authentication at first to just test the POST before adding in security/authentication. … Read more

Change the headers content type with wp_remote_post

So, you set the headers of a request using wp_remote_post() and you expect that headers be used in the response. That is what I understand from you: When I print the response content-type is still “text/html” I think that you are missunderstanding the HTTP headers. Using wp_remote_post() you make a request and you can set … Read more