I’ve been trying to use wp_remote_get for the first time and having some troubles.
So far I’m testing the response with this code:
<?php
$url = "https://webapieu3.filefinderanywhere.com/SeussConsultingTestWebportAPI/xml/AllActive";
$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);
}
?>
Prior to adding the sslverify param, is_wp_error returned true, but now it’s returning false, however I’m getting the following response:
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 00:56:09 GMT
[connection] => close [content-length] => 61 )
[body] => {"Message":"Authorization has been denied for this request."}
[response] => Array (
[code] => 401
[message] => Unauthorized )
[cookies] => Array ( )
[filename] => )
Why is there a 401 error after I’ve already passed authentication? And how do I pass authentication?
1 comment
Comments are closed.