• Hi, I’m developing a plugin and have a need to post to an API and include an Authorization header.

    	
    $basicauth = 'Basic ' . base64_encode( $client_id . ':' . $client_secret );
    
    $headers = array( 
    		'Authorization' => $basicauth,
    		'Content-type' => 'application/json',
    		'Content-length' => $contentlen
    		);
    
    $pload = array(
    	'method' => 'POST',
    	'timeout' => 30,
    	'redirection' => 5,
    	'httpversion' => '1.0',
    	'blocking' => true,
    	'headers' => $headers,
    	'body' => $bdy,
    	'cookies' => array()
    	);
    
    $response = wp_remote_post($url, $pload);
    

    So since the remote was returning to me a 500 I decided to post to myself to see what I’m sending.

    This is what pload is looking like:

    
    pload: Array
    (
        [method] => POST
        [timeout] => 30
        [redirection] => 5
        [httpversion] => 1.0
        [blocking] => 1
        [headers] => Array
            (
                [Authorization] => Basic NzYblahblahblahblah0YjQzZg==
                [Content-type] => application/json
                [Content-length] => 132
            )
    
        [body] => {"code":"Niu","grant_type":"authorization_code","redirect_uri":"http:\/\/blahblahblah"}
        [cookies] => Array
            (
            )
    
    )
    

    Some field data has been changed to protect the innocent.

    But when I print out the headers received using apache_request_headers() I see everything except the Authentication header.

    
    headers : Array
    (
        [Content-Length] => 132
        [Content-Type] => application/json
        [Accept] => */*
        [Accept-Encoding] => deflate, gzip
        [Connection] => close
        [Host] => blhblahblahblah
        [Referer] => https://blahblahblah
        [User-Agent] => WordPress/4.9.2; https://blahblahblah
    )
    
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_remote_post & Authorization header’ is closed to new replies.