4

Hey am new to WP development, can any one tell me how to add request headers in wp_remote_get() or wp_remote_post() remote api calls.

I tried the following but didnt work

    $response = wp_remote_get( add_query_arg( array(
        'Affiliate-Id' => XXXXX,
        'Affiliate-Token'     => XXXXX
    ), $api_url ) , array( 'timeout' => 10));
11

If you want to send Affiliate-Id and Affiliate-Token in headers then you need to pass them in the optional arguments of wp_remote_get function.

Example:

$response = wp_remote_get( $api_url ,
             array( 'timeout' => 10,
            'headers' => array( 'Affiliate-Id' => XXXXX,
                               'Affiliate-Token'=> XXXXX ) 
             ));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.