admin管理员组文章数量:1122832
Need to read json data from a url. But it's has 3 login parameter. I've tried below but not working.
$username = "XXXXXXXX";
$password = "XXXXXXXX";
$client_id = "XXXXXXX";
$url = "1.php";
$context = stream_context_create(array(
"http" => array(
"header" => "Authorization: Basic " . base64_encode("$username:$password:$client_id")
)));
$data = file_get_contents($url, false, $context);
echo $data;
What I'm doing wrong?
Need to read json data from a url. But it's has 3 login parameter. I've tried below but not working.
$username = "XXXXXXXX";
$password = "XXXXXXXX";
$client_id = "XXXXXXX";
$url = "1.php";
$context = stream_context_create(array(
"http" => array(
"header" => "Authorization: Basic " . base64_encode("$username:$password:$client_id")
)));
$data = file_get_contents($url, false, $context);
echo $data;
What I'm doing wrong?
Share Improve this question asked yesterday Ripa SahaRipa Saha 2,5406 gold badges28 silver badges54 bronze badges 1- I don't like the authorization header generation. It should be just username:password. Carefully review the documentation of the API you want to use. – mr mcwolf Commented yesterday
1 Answer
Reset to default 0Pass client_id as a Query Parameter
$url = "1.php?client_id=" . urlencode($client_id);
$context = stream_context_create(array(
"http" => array(
"header" => "Authorization: Basic " . base64_encode("$username:$password")
)));
$data = file_get_contents($url, false, $context);
echo $data;
Try this Hope it works!
本文标签: file get contentsfilegetcontents not working in json readStack Overflow
版权声明:本文标题:file get contents - file_get_contents not working in json read - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281414a1926310.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论