将数据发送到OAUTH服务器后,PHP Curl请求返回“来自服务器的空答复”

时间:2019-06-19 20:53:07

标签: php curl oauth

问题是产生的错误-当我执行以下PHP代码尝试从其服务器请求一些数据时,会出现“来自服务器的空回复”

我试图通过删除字符串周围的'http_build_query'部分来更改数据。这样做后,请求已发送,但服务器不喜欢该数据,因此我必须输入“ http_build_query”。 我需要程序返回其他消息,而不是以下消息

Empty reply from server

OR

{ "errorCode" : "errors.com.epicgames.common.oauth.unsupported_grant_type", "errorMessage" : "Unsupported grant type: null", "messageVars" : [ ], "numericErrorCode" : 1016, "originatingService" : "com.epicgames.account.public", "intent" : "prod", "error_description" : "Unsupported grant type: null", "error" : "unsupported_grant_type" }

=>如果没有“ http_build_query”,则会发生这种情况。

重现问题的最小代码:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$data = http_build_query(array(
 'grant_type' => "password",
 'username' => "<EMAIL>",
 'password' => "<PASSWORD>",
 'includePerms' => true
));
/* Public Auth Client Token */
$headers = [
    'Authorization: basic MzQ0NmNkNzI2OTRjNGE0NDg1ZDgxYjc3YWRiYjIxNDE6OTIwOWQ0YTVlMjVhNDU3ZmI5YjA3NDg5ZDMxM2I0MWE=',
    'Content-type: application/x-www-form-urlencoded',
    'Content-Length: 100',
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/token");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);  //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
/*curl_setopt($ch, CURLOPT_TIMEOUT, 5);*/

$server_output = curl_exec ($ch);
if (curl_error($ch)) {
    $error_msg = curl_error($ch);
    echo($error_msg);
}

curl_close ($ch);
print  $server_output ;
?>

期望的输出是任何内容,而不是已经显示的两条消息。

0 个答案:

没有答案