V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hopestar86
V2EX  ›  问与答

请教 PHP curl 抓取数据的问题

  •  
  •   hopestar86 · 2020-04-09 15:23:28 +08:00 · 777 次点击
    这是一个创建于 1471 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://api.mxc.io/swap/depth?count=100&instrumentID=10

    直接浏览器访问,能有数据, 但是用 file_get_contents 或者 curl 都获取不到

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL, "https://api.mxc.io/swap/depth?count=100&instrumentID=10");

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

    curl_setopt($ch,CURLOPT_HEADER,0);

    curl_setopt($ch, CURLOPT_TIMEOUT,60);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

    echo $output = curl_exec($ch);

    curl_close($ch);

    2 条回复    2020-04-09 15:38:34 +08:00
    hcymk2
        1
    hcymk2  
       2020-04-09 15:34:55 +08:00
    Content-Encoding: gzip
    hopestar86
        2
    hopestar86  
    OP
       2020-04-09 15:38:34 +08:00
    @hcymk2 curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2870 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 00:06 · PVG 08:06 · LAX 17:06 · JFK 20:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.