Sending a post request with JSON content type


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

    $args = array(
        'headers' => array(
            'content-type' => 'application/json'
        'body'    => array(
            'urls' => json_encode('{"urls": [""]}')
        'cookies' => array()
    $response = wp_remote_post( $url, $args );

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

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

enter image description here

228 11 months 2022-03-18T17:38:10-05:00 0 Answers 0 views 0

Leave an answer