簡體   English   中英

在PHP中從404獲取響應正文

[英]Get response body from 404 in PHP

我正在與Battle.net API交互,當我打到404頁面時,我需要獲取響應正文。 問題是我得到一個錯誤。

我知道頁面具有主體,如文檔中所示,有一個具有主體的示例(下面的屏幕截圖)。 我還輸入了我的php錯誤的屏幕截圖。 任何幫助,將不勝感激。

Battle.net文件

這是我的代碼:

$ responseCode = get_http_response_code($ api); //檢查頁面是否存在

if($responseCode == 200) { //Page exists
    $api = "battle.net/apirequest.......";
    $json = file_get_contents($api);
    $schema = json_decode($json, true);

    $completeQuests = $schema['quests'];
} else if ($responseCode == 404) {
     ...Trying to find out why here.....
}

謝謝,James McNee

編輯:另外,當我直接轉到URL時,我會得到JSON響應,所以我真的不知道此錯誤來自何處。

file_get_content不允許您在失敗的情況下獲取內容。 要獲得內容,您將必須使用較低級別的庫。 像說卷曲。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM