questions

How to make http request using php in wordpress plugin?

Rate this post

I want to make http request using php in wordpress plugin here is my code

$request = wp_remote_post('https://en0ctqi09fhu7m.x.pipedream.net/', array(
                'headers' => array('Accept' => 'application/json'),
                'body' => array('data_type' => 'customer', )
            ));

but in the body i want to send this data

{
    "data_type:": "customer",
    "customer": {
        "id": 123,
        "first_name": "John",
        "last_name": "Doe",
        "email": "[email protected]",
        "address": "18/XII, Light Avenue, Upper Manhattan, NY"
    }
}

I’m getting confused how to send data in body section

 

✔️Solution:

Try this :

$response = wp_remote_post( $url, array(
    'method'      => 'POST',
    'headers' => array('Accept' => 'application/json'),
    'timeout'     => 45,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking'    => true,
    'body'        => array(
        'data_type' => 'customer',
        'customer' => array(
            "id" => 123,
            "first_name" => "John",
            "last_name" => "Doe",
            "email" => "[email protected]",
            "address" => "18/XII, Light Avenue, Upper Manhattan, NY"
        )
    )
));

Leave a Reply

Your email address will not be published.

Back to top button