Why does wp_remote_post returns an empty body response on certain endpoints?

Im gonna make this brief;

Im using wp_remote_post to do a POST request to an external API. My local development environment looks something like http://website.test. As of now I am requesting to a QA version of this API so the protocol of the endpoints is HTTP. The problem is that the $response object always returns an empty body. If I copy the exact request JSON that im sending over, and the exact HTTP URL of the API, and use it on Postman, I get a normal body response with no issues. So why is the wp_remote_post giving me an empty body?

This is how im doing the request:

    $response = wp_remote_post( $url_motor . '/' . $this-venta_ep , array(
                    'headers'     = array('Content-Type' = 'application/json' , 'Accept'     = 'application/json'),
                    'body'        = wp_json_encode($params),
                    'method'      = 'POST',
                    'data_format' = 'body',
                )
            );

I'm assuming it could have something to do with the fact that its not over HTTPS (neither my local environment, nor the API, but as I said, it works as intended on Postman). I already tried the blocking and the sslverify options.

Another theory that I have is that it might have something to do with the request body that I am sending over. This is because I am using other endpoints of the same API over HTTP, and some of them DO send a non-empty body back. The pattern that I noticed is that the endpoints that do return a body are the endpoints on which I send an array like this:

$arg = wp_json_encode([
    single_item_json = [ 1 , 2 , 3]   
])

A simple array with one index that contains an array seems to work. But when I send something like this:

$arg = wp_json_encode([
    multiple_item_json = [ 1 , 2 , 3],   
    multiple_item_json = [ 1 , 2 , 3],   
])

This one seems to get back an empty body.

I know that my two theories are extremely different, but at this point any kind of insight would be of great help. As I said, what throws me off is that the same request body that gets an empty response body with wp_remote_post, when used on Postman, it does get a non-empty , valid response body, so it couldnt possibly be the API, right?

Anyways, thank you for your time and I hope I made my issue clear.

Topic http json api plugin-development Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.