Sending a post request with JSON content type

Question

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

$url="http://localhost:4000/";
    $args = array(
        'headers' => array(
            'content-type' => 'application/json'
        ),
        'body'    => array(
            'urls' => json_encode('{"urls": ["https://www.sampledomain.com/"]}')
        ),
        '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

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

Leave an answer

Browse
Browse