【问题标题】:HTTPS REQUEST WITH stream_context_create()带有 stream_context_create() 的 HTTPS 请求
【发布时间】:2018-06-14 11:26:00
【问题描述】:

我的代码有问题,我得到的错误是:

警告:fopen(https://discordapp.com/api/v6/auth/login):打开流失败:HTTP 请求失败! HTTP/1.1 400 错误请求 C:\xampp\htdocs\s2.php 第 15 行

以下是相关代码:

<?php
$data = array("email" => 'Email@gmail.com', "password" => 'Password');
$data_string = json_encode($data);                                                                                   
$context_options = array (
        'https' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/json\r\n"
                . "Content-Length: " . strlen($data_string). "\r\n",
                 'content' => $data_string

            )
        );

$context = stream_context_create($context_options);
$fp = fopen('https://discordapp.com/api/v6/auth/login', 'r', false, $context);

?>

感谢您的帮助!

【问题讨论】:

    标签: php curl login https


    【解决方案1】:

    似乎不再允许通过机器人直接登录,因为您应该使用 Discord 的 OAuth2 (how does OAuth2 work?) 功能。这意味着您的机器人需要在您的 Discord 帐户中进行设置,然后您可以在机器人上使用基于令牌的访问权限来针对 Discord 对外部应用程序进行身份验证。 不再允许基于机器人的登录的更改发生在 2017 年初左右,那时所有基于 PHP 的 Discord 相关的 Github 应用程序都停止维护。 Here 是关于禁止使用自动登录的机器人的讨论和评论,this one 是关于必须使用 OAuth2 的讨论和评论。

    the Discord OAuth2 chapter 中阅读有关身份验证和机器人的更多信息。

    如果您能详细说明您计划实现的目标,也许我们可以帮助您找到解决任务的方法。


    以前(不再有效)的答案:

    我没有使用过 DiscordApp,所以我还没有尝试过。您是否尝试过将值作为 FORM 值发布到 API,而不是发送 JSON 编码的数据?

    $postData = array(
      'email' => 'Email@gmail.com', 
      'password' => 'Password'
    );
    $params = array('https' =>
      array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postData
      )
    );
    
    $context  = stream_context_create($params);
    
    // get the entire response ...
    $result = file_get_contents('https://discordapp.com/api/v6/auth/login', false, $context);
    
    // ... or alternatively using fopen()
    $fp = fopen('https://discordapp.com/api/v6/auth/login', 'r', false, $context);
    

    我还没有找到任何关于如何将参数传递到login URI 的文档,但至少这是可以使用基于表单的普通登录的方式。

    根据DiscordApp Response codes,如果调用未被理解(调用不存在的函数)或参数发送不正确,则可能会收到 400,因此您应该了解如何使用参数调用logininterface使用脚本。

    【讨论】:

    • 感谢 SaschaM78 !
    猜你喜欢
    • 1970-01-01
    • 2012-02-06
    • 1970-01-01
    • 2018-03-11
    • 2013-12-01
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多