gpt4 book ai didi

php - wp_remote_get() 未通过身份验证

转载 作者:可可西里 更新时间:2023-11-01 15:22:54 28 4
gpt4 key购买 nike

我第一次尝试使用 wp_remote_get 时遇到了一些麻烦。

到目前为止,我正在使用这段代码测试响应:

<?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);
}

?>

在添加 sslverify 参数之前,is_wp_error 返回 true,但现在它返回 false,但我收到以下响应:

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] => )

为什么我已经通过了身份验证却出现401错误?以及如何通过身份验证?

最佳答案

$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 );

关于php - wp_remote_get() 未通过身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33990046/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com