第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

讀取簡(jiǎn)單的 API 返回空白屏幕?

讀取簡(jiǎn)單的 API 返回空白屏幕?

PHP
浮云間 2022-07-16 16:55:28
出于某種原因,我無(wú)法弄清楚如何在任何地方在線解決這個(gè)問(wèn)題?我有這個(gè)簡(jiǎn)單的免費(fèi)查克諾里斯笑話 api,我只是想輸出它的 json,但它不起作用?我只是得到一個(gè)空白屏幕?在控制臺(tái)中,網(wǎng)絡(luò)選項(xiàng)卡顯示 200 ok 并且標(biāo)頭有效?我究竟做錯(cuò)了什么?我的代碼:<?php  header('Content-Type: application/json');  header('X-RapidAPI-Host: matchilling-chuck-norris-jokes-v1.p.rapidapi.com');  header('X-RapidAPI-Key: 341b5c1156msh6827bf7184ef4ddp1c8d09jsnbc52db5d01be');  $str = file_get_contents('https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random');// decode JSON$json = json_decode($str, true);// get the dataprint_r($json);
查看完整描述

1 回答

?
慕無(wú)忌1623718

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊

您很可能想發(fā)送這些標(biāo)頭...


header在本地打印標(biāo)題給你,你在哪里執(zhí)行它。


有了file_get_contents它會(huì)是這樣的:


<?php

$opts = [

    "http" => [

        "method" => "GET",

        "header" => "Content-Type: application/json\r\n" .

            "X-RapidAPI-Host: matchilling-chuck-norris-jokes-v1.p.rapidapi.com\r\n" .

            "X-RapidAPI-Key: 341b5c1156msh6827bf7184ef4ddp1c8d09jsnbc52db5d01be\r\n"

    ]

];


$context = stream_context_create($opts);

$str = file_get_contents('https://matchilling-chuck-norris-jokes-v1.p.rapidapi.com/jokes/random', false, $context);


// decode JSON

$json = json_decode($str, true);


// get the data

print_r($json);

我還建議切換到curl擴(kuò)展。


查看完整回答
反對(duì) 回復(fù) 2022-07-16
  • 1 回答
  • 0 關(guān)注
  • 112 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)