【问题标题】:GET Request with params: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden带参数的 GET 请求:无法打开流:HTTP 请求失败! HTTP/1.0 403 禁止
【发布时间】:2016-06-28 21:06:14
【问题描述】:

我正在尝试使用 Steam API 提供的新功能,但遇到了问题,我认为这是一个普遍问题,而不是与实际服务相关的问题。

我不断得到:

打开流失败:HTTP 请求失败! HTTP/1.0 403 禁止

我正在尝试使用以下参数发送 GET 请求:

<?php

    $url = "https://api.steampowered.com/ICSGOTournaments_730/GetTournamentItems/v1?key=".$_SESSION['steam_appid']."&event=9&steamid=".$_SESSION['steam_steamid']."&steamidkey=".$_SESSION['userAuthCode'];
    $response = file_get_contents($url);
    echo($response);

?>

我 100% 确定参数是正确的,我认为这与我的代码有关,而不是 Steam 本身。

当我尝试使用相同的代码但不同的 API 调用时:

$url = "https://api.steampowered.com/ICSGOTournaments_730/GetTournamentLayout/v1?key=".$_SESSION['steam_appid']."&event=9";

执行良好并返回数据,因此它与其他两个参数相关。

我想知道我构建 URL 的方式有什么问题吗?

会话文件(第 3 方):

<?php
if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname'])) {
    require 'SteamConfig.php';
    $url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$_SESSION['steamid']); 
    $content = json_decode($url, true);
    $_SESSION['steam_appid'] = $steamauth['apikey'];
    $_SESSION['steam_steamid'] = $content['response']['players'][0]['steamid'];
    $_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
    $_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
    $_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
    $_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
    $_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
    $_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
    $_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
    $_SESSION['steam_avatarfull'] = $content['response']['players'][0]['avatarfull'];
    $_SESSION['steam_personastate'] = $content['response']['players'][0]['personastate'];
    if (isset($content['response']['players'][0]['realname'])) { 
           $_SESSION['steam_realname'] = $content['response']['players'][0]['realname'];
       } else {
           $_SESSION['steam_realname'] = "Real name not given";
    }
    $_SESSION['steam_primaryclanid'] = $content['response']['players'][0]['primaryclanid'];
    $_SESSION['steam_timecreated'] = $content['response']['players'][0]['timecreated'];
    $_SESSION['steam_uptodate'] = time();
    include 'mysql_connection.php';
        $userAuth = getAuth();
        if($userAuth != false){
            $_SESSION['userAuthCode'] = $userAuth;
        }
        else{
            $_SESSION['userAuthCode'] = "Unset";
        }
}

$steamprofile['steamid'] = $_SESSION['steam_steamid'];
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
$steamprofile['avatarfull'] = $_SESSION['steam_avatarfull'];
$steamprofile['personastate'] = $_SESSION['steam_personastate'];
$steamprofile['realname'] = $_SESSION['steam_realname'];
$steamprofile['primaryclanid'] = $_SESSION['steam_primaryclanid'];
$steamprofile['timecreated'] = $_SESSION['steam_timecreated'];
$steamprofile['uptodate'] = $_SESSION['steam_uptodate'];
?>

【问题讨论】:

  • 你能发布/显示会话数组吗?
  • 您是否在php.ini 中启用了php_openssl 扩展
  • @RiggsFolly 好吧,我没有手动启用它,但我只是做了 phpinfo(),它说 openSSL Support: Enabled。
  • @RavinderReddy 添加了有问题的会话。

标签: php steam


【解决方案1】:

file_get_contents - 使用 https 需要使用:

来自php.net

When using SSL, Microsoft IIS will violate the protocol by closing the 
connection without sending a close_notify indicator. PHP will report 
this as "SSL: Fatal Protocol Error" when you reach the end of the 
data. To work around this, the value of error_reporting should be 
lowered to a level that does not include warnings. PHP can detect 
buggy IIS server software when you open the stream using the https:// 
wrapper and will suppress the warning. When using fsockopen() to 
create an ssl:// socket, the developer is responsible for detecting 
and suppressing this warning.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2012-12-31
    • 1970-01-01
    相关资源
    最近更新 更多