【发布时间】:2013-10-24 11:52:54
【问题描述】:
从我的服务器向 google.com 发布请求时出现以下错误:
警告:file_get_contents(http://accounts.google.com):打开流失败:HTTP 请求失败! HTTP/1.0 405 Method Not Allowed in C:\...\index.php on line 23
我的代码如下:
$postdata = http_build_query(
array(
'code' => '####',
'client_id' => '####',
'client_secret' => '####',
'grant_type' => 'authorization_code'
)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://accounts.google.com', false, $context);
echo $result;
【问题讨论】:
-
不要发布凭据 :)
-
好吧,你应该在这里联系谷歌。根据 RFC 1945,HTTP/1.0 没有 405 错误代码,因此适用 4xx 类:tools.ietf.org/html/rfc1945#section-9.4 - HTTP/1.1 中的“猜测”(具有 405 代码),此处对此进行了解释:tools.ietf.org/html/rfc2616#section-10.4.6
-
已经在 google 报告了这个问题。等待他们的回应。虽然当我使用“fopen”或“curl”时它没有给出任何错误但它给出了空响应。
标签: php oauth-2.0 httpcontext google-authentication