Sending a POST request with JSON content type

I’m trying to send a post request to a locally hosted app that generates important CSS. Here is the code which I am using.

$url="http://localhost:4000/";
$urls->urls="https://www.domain.com";
$data = wp_remote_post($url, array(
    'headers'     => array('Content-Type' => 'application/json; charset=utf-8'),
    'body'        => json_encode($urls),
    'method'      => 'POST',
    'data_format' => 'body',
));

It returns this error: SyntaxError: Unexpected token at position 0 in JSON.

Here’s a working example in Postman. Any thoughts on why my code isn’t working?

Leave a Comment