hopestar86
V2EX  ›  问与答

请教 PHP curl 抓取数据的问题

  •  
  •   hopestar86 · Apr 9, 2020 · 1652 views
    This topic created in 2229 days ago, the information mentioned may be changed or developed.

    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 replies    2020-04-09 15:38:34 +08:00
    hcymk2
        1
    hcymk2  
       Apr 9, 2020
    Content-Encoding: gzip
    hopestar86
        2
    hopestar86  
    OP
       Apr 9, 2020
    @hcymk2 curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); 谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1355 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:00 · PVG 01:00 · LAX 10:00 · JFK 13:00
    ♥ Do have faith in what you're doing.