• Hello
    I’m attempting to use wp_remote_get for the first time
    Really, this is my first major api job, so I’m just trying to get a grasp of deeper parts of API connections, PLUS wp_remote_get

    The code I’m using to attempt to attempt to the api is as follows:

    <?php
    						$url      = "url";
    						$username = "username";
    						$password = "password";
    						$headers = array( "Authorization" => "Basic " . base64_encode( "$username:$password" ), "sslverify" => false );
    						$response = wp_remote_get($url, $headers);
    
    						if (is_wp_error($response)){
    							echo $response->get_error_message();
    						}else{
    							print_r($response);
    						}
    
    					 ?>

    I had originally tried without “sslverify”, but it would fail authentication.

    Adding in sslverify goes to the else part of the function, but returns the following:

    Array ( [headers] => Array ( [cache-control] => no-cache [pragma] => no-cache [content-type] => application/json; charset=utf-8 [expires] => -1 [server] => Microsoft-IIS/7.5 [www-authenticate] => Basic [x-aspnet-version] => 4.0.30319 [x-powered-by] => ASP.NET [date] => Mon, 30 Nov 2015 22:40:16 GMT [connection] => close [content-length] => 61 ) [body] => {"Message":"Authorization has been denied for this request."} [response] => Array ( [code] => 401 [message] => Unauthorized ) [cookies] => Array ( ) [filename] => )

    It seems like authentication has failed.. but hasn't it already passed? Am I missing params somewhere in the original call?

Viewing 1 replies (of 1 total)
  • Hi,

    And the mistake is………

    $response = wp_remote_get($url, $headers);
    doesn’t take headers, but Args Array :

    $args = array(
      'headers' => array(
       "Authorization" => "Basic " . base64_encode( "$username:$password" )
      )
      ,"sslverify" => false
    );
    $response = wp_remote_get($url, $args);

    And you begin to fell betters.
    Just check too, sslverify is in args array not headers.

    See you, space cowboy

Viewing 1 replies (of 1 total)
  • The topic ‘wp_remote_get passing authentication, but then failing in body’ is closed to new replies.