iT邦幫忙

0

PHP 取得HTTP錯誤代碼方式?

取得HTTP錯誤代碼方式?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
2
dragonH
iT邦超人 5 級 ‧ 2020-07-31 09:41:10
最佳解答

code

<?php
    $url = "https://covid19dashboard.cdc.gov.tw/dash3";
    $resutlt1 = file_get_contents($url);
    $resutlt1_json = json_decode($resutlt1, true);
    print_r("確診: ".$resutlt1_json[0]["確診"]);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result2 = curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $result2_json = json_decode($result2, true);
    print_r("\nstatusCode:".$httpcode);
    print_r("\n送驗: ".$result2_json[0]["送驗"]);
    curl_close($ch);

result

確診: 467
statusCode:200
送驗: 81,587
看更多先前的回應...收起先前的回應...
QR摳 iT邦新手 5 級 ‧ 2020-07-31 10:11:32 檢舉

..我上次的問題已解答了XD

QR摳 iT邦新手 5 級 ‧ 2020-07-31 10:12:48 檢舉

感謝~

dragonH iT邦超人 5 級 ‧ 2020-07-31 10:14:38 檢舉

摳宇

沒喔

我這次有多一行

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

QR摳 iT邦新手 5 級 ‧ 2020-07-31 13:48:08 檢舉

...好喔XD

1
阿展展展
iT邦好手 1 級 ‧ 2020-07-31 06:24:29

http_response_code ([ int $response_code ] ) : mixed

1
Max邁可思
iT邦新手 5 級 ‧ 2020-07-31 09:51:26

哈囉你好~
我有試著找到一些資料不知道確定是不是你需要的...
但希望可以幫助到你~

(https://blog.hoyo.idv.tw/?p=3036)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $m3u8);
curl_setopt($ch, CURLOPT_REFERER, 'http://hichannel.hinet.net/radio/index.do' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
 
// 不可用資源回傳 410
if ( $info['http_code'] == '200' ) {
    echo $m3u8;
    break;
}
else {
    //echo $m3u8;
    echo $i++;
    //sleep(1);
}
QR摳 iT邦新手 5 級 ‧ 2020-07-31 10:12:37 檢舉

感謝!

我要發表回答

立即登入回答