微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在标头php中使用x-auth-token发送请求

如何将“x-auth-token”参数发送到带有YII标头的服务器.

我有这个代码

$data = array('customerId' => $userId);

        $getdata = http_build_query(
            $data 
        );      

        $options = array('http' =>
             array(
                'method'  => 'GET',
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n".
                " Authorization: x-auth-token ".$token." \r\n",
                'content' => $getdata
            )
        );

        $context  = stream_context_create($options);
        $result = file_get_contents('url?'.$getdata, false, $context);

在Android中,我们发送的数据类似于request.addHeader(“x-auth-token”,token);

我无法访问服务器,我只是发送请求和获取数据.但登录后我需要发送登录令牌来获取数据,但它返回403.

所以我认为它不是发送令牌.我怎样才能做到这一点?

解决方法:

$headers = array();
$headers[] = "x-auth-token: $token";
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
$state_ch = curl_init();
    curl_setopt($state_ch, CURLOPT_URL,"url");
    curl_setopt($state_ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($state_ch, CURLOPT_HTTPHEADER, $headers);
    $state_result = curl_exec ($state_ch);
    $state_result = json_decode($state_result); 

我用CURL完成了它

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐