为什么我在file_get_contents中收到错误“ HTTP / 1.0 463”

问题描述 投票:0回答:1

我正在尝试从Habbo API中提取文本内容,但收到错误警告:file_get_contents(https://www.habbo.it/api/public/users?name=Adaara):无法打开流:HTTP请求失败! HTTP / 1.0 463 HTTP请求在file_get_contents中失败。

<?php
error_reporting(E_ALL);
$url = "https://www.habbo.it/api/public/users?name=Adaara";
$json = file_get_contents($url);
$json = json_decode($json, true);
echo $json['motto'];
?>

我希望打印数组的座右铭值。预先感谢您的回答。

php webserver user-agent
1个回答
0
投票

尝试使用cURL;它非常便携/可靠!

<?php

error_reporting(E_ALL);

$url  = 'https://www.habbo.it/api/public/users?name=Adaara';

$handle = curl_init($url);

curl_setopt_array(
  $handle,
  [
    CURLOPT_HTTPHEADER => ['Content-Type' => 'application/json'],
    CURLOPT_USERAGENT => 'Mozilla/1.22 (compatible; MSIE 5.01; PalmOS 3.0) EudoraWeb 2',
    CURLOPT_RETURNTRANSFER => true,
  ]
);

$data = curl_exec($handle);
$json = json_decode($data, true);

echo $json['motto'];
© www.soinside.com 2019 - 2024. All rights reserved.