【问题标题】:Why I get the error "HTTP/1.0 463" in file_get_contents为什么我在 file_get_contents 中收到错误“HTTP/1.0 463”
【发布时间】:2020-01-30 05:42:21
【问题描述】:

我正在尝试从 Habbo API 中提取文本内容,但我收到错误警告:file_get_contents (https://www.habbo.it/api/public/users?name=Adaara): failed to open stream: HTTP request failed! 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】:

改用 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'];

【讨论】:

    猜你喜欢
    • 2014-03-15
    • 2012-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2011-06-04
    • 1970-01-01
    • 2022-10-02
    • 1970-01-01
    相关资源
    最近更新 更多