1 回答

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ò)展。
- 1 回答
- 0 關(guān)注
- 112 瀏覽
添加回答
舉報(bào)