wp_remote_post doesn’t work with more than 1024 bytes in the body

If you happen to be using the CURL transport, then it sometimes has minor problems sending POST requests greater than 1024 characters. More info here:

https://stackoverflow.com/questions/463144/php-http-post-fails-when-curl-data-1024

The fix suggested there is to send an empty Expect: header. You can do this by modifying your code thusly:

$response = wp_remote_post( $url,
    array(
      'timeout' => 60,
      'redirection' => 5,
      'blocking' => true,
      'headers' => array(
        'Content-Type' => 'application/json',
        'Expect' => '',
      ),
      'body' => 'bla bla (...)' // fails if larger than 1024
    )
  );

Edit: more info:

Some versions of curl and PHP, when you put in more than 1024 characters in the body, will send the headers first and then an “Expect: 100-continue” header. A webserver receiving this then should respond with a 100 Continue status for the client to continue to send the rest of the body.

If you’re using a real webserver, then it will send that response to receive the rest of the message. Some older webservers did not do this, thus the given workaround in that previous question.

I don’t know what ngrok is, but I’m betting it is not responding like a normal webserver here. Without that server saying to continue the POST, curl waits for it to do so. It times out eventually.