Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 198 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wp_remote_get() not passing authentication

#1
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?
Reply

#2
$wp_request_headers = array(
'Authorization' => 'Basic ' . base64_encode( 'username:password' )
);

$wp_request_url = 'http://localserver/wordpress-api/wp-json/wp/v2/posts/52';

$wp_delete_post_response = wp_remote_request(
$wp_request_url,
array(
'method' => 'DELETE',
'headers' => $wp_request_headers
)
);

echo wp_remote_retrieve_response_code( $wp_delete_post_response ) . ' ' . wp_remote_retrieve_response_message( $wp_delete_post_response );
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through