如何将“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完成了它
标签:php,yii
来源: https://codeday.me/bug/20190824/1709506.html