2017-04-23 3 views
0

しばらくの間苦労しました。不和から私のトークンを取得しようとしています。PHPのOAuthリクエストを不一致にする

私が間違っている場所を教えてください。 file_get_contents(https://discordapp.com/api/oauth2/authorize):

<?php 
ini_set('display_errors',1); 

$code = ''; 
$code = $_GET['code']; 

if(isset($code)){ 

$postData = array(
    'code' => $code, 
    'client_id' => "[omitted]", 
    'client_secret' => '[omitted]', 
    'redirect_uri' => '[omitted]' 
); 

// Create the context for the request 
$context = stream_context_create(array(
    'http' => array(
     // http://www.php.net/manual/en/context.http.php 
     'method' => 'POST', 
     'content' => $postData, 
       'header' => "Authorization: Bot [omitted]\r\n". 
     "Content-Length: ".strlen($postData)."\r\n", 
    ) 
)); 

// Send the request 
$response = file_get_contents('https://discordapp.com/api/oauth2/authorize', FALSE, $context); 

echo $response; 

} else { 
    echo '<a href="https://discordapp.com/oauth2/authorize?response_type=code&redirect_uri=[omitted]&scope=identify%20guilds&client_id=[omitted]">Login</a>'; 
} 

私はエラー

警告を得続けるストリームをオープンに失敗しました:HTTPリクエストが失敗しました! HTTP/1.1 411の長さが/index.phpの27行目で必要です

答えて

0

strlenは配列上で失敗していますか?私は他の人が何かを使用しているのを見たことがあります。

$postData = http_build_query(array('foo'=>'bar'))