鲍成龙
使用
参数 | 数据类型 | 是否必需 | 描述 | 默认值 |
---|---|---|---|---|
$url | 字符串 | 是 | 请求 | 无 |
$args | 数字 | 否 | 请求参数 | array() |
返回值
响应数组,如果出错,返回
使用示例
发送的
$response = wp_remote_post( $url, array(
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array(
'username' => 'bob',
'password' => '1234xyz'
),
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
在请求中添加基础授权数据
如果需要添加基础授权数据,参考下面的代码在
$response = wp_remote_post( $url, array(
'body' => $data,
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ),
),
) );
查看更多
赞
评论