【问题标题】:file_get_contents working in HTTP but not under HTTPSfile_get_contents 在 HTTP 下工作,但不在 HTTPS 下
【发布时间】:2014-03-17 16:24:24
【问题描述】:
$newLogUrl = SERVER URL PATH
$opt = array('http' => array(
             'method'  => "POST",
             'header'  => 'Content-type: application/json',
             'content' => $jsonCredenObj,
             'timeout' => 4));
$context = stream_context_create($opt);

$response = file_get_contents($newLogUrl,false,$context); 

上面的代码在普通的http中工作,但在安全服务器https中不工作

错误

Warning: file_get_contents(): failed to open stream: HTTP request failed! HTTP/1.1 405 Method Not Allowed

【问题讨论】:

标签: php arrays function http https


【解决方案1】:

405 方法不允许

Request-Line 中指定的方法不允许用于 由 Request-URI 标识的资源。响应必须包含一个 允许包含请求的有效方法列表的标头 资源。 同样正如MarcB 提到的,您连接的相应URL 不接受POST 方法。

Source : www.w3.org

始终检查标头的 URL 以查看它们接受的方法等。您可以为此使用 $http_response_header..

<?php
file_get_contents('http://thatremoteurl.com');
var_dump($http_response_header);

使用 HTTPS 网址

您需要在您的 PHP.ini 上启用 openssl 扩展。

打开你的 PHP.ini 并检查这一行 ;extension=php_openssl.dll 。删除它前面的分号并保存您的文件并重新启动您的网络服务器。

【讨论】:

    猜你喜欢
    • 2014-09-02
    • 1970-01-01
    • 2012-03-20
    • 2013-08-18
    • 2020-02-18
    • 1970-01-01
    • 2019-03-14
    • 2019-10-12
    • 2014-07-05
    相关资源
    最近更新 更多