doudihuang7642 2016-11-09 20:49
浏览 40
已采纳

使用PHP使用curl获取JSON数据

I am trying to use PHP to get JSON data using curl, however I am getting error 302, and am not getting data returned.

I can execute the curl at the command line using:

curl -X GET --header "Accept: application/json" "https://api.lootbox.eu/pc/us/Hydropotamus-1777/profile"

The following is the PHP script that is currently not working:

<?php
// Get cURL resource
$url = 'https://api.lootbox.eu/pc/eu/Hydropotamus-1777/profile';
$curl = curl_init($url);
echo "A";
// Set some options - we are passing in a useragent too here
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  'Accept: application/json'
));
echo "B";

$resp = curl_exec($curl);
echo "C";
echo $resp;
// Close request to clear up some resources
curl_close($curl);
 ?>

Below are a few environment details that may be helpful:

  • Windows 10
  • PHP 5.6.24
  • Chrome browser
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥40 python,计算机程序运行结果很奇怪
      • ¥15 有关时间计算器的问题
      • ¥200 Chrome浏览器自动保存密码需要解密!来人
      • ¥18 关于#c语言#的问题:如何把下面几个代码放在一起编序号,然后输入对应数字运行对应代码,还可以返回重输
      • ¥30 windows下无法运行go test的问题
      • ¥15 多个Rigify骨骼 导入一起 后 没有 控制器面板
      • ¥15 想问一下sprak ada语言的pre和post怎么设
      • ¥15 使用python将分子模拟输出.gro文件
      • ¥15 港诡实录的背包系统拆解
      • ¥15 宽带IP网络路由器的初始路由表和最终路由表