无法找到套接字传输“https”
我用它来检查 URL 的可用性:
$fp = fsockopen($url, 443, $errno, $errstr);
然后我收到此错误...
警告:fsockopen() [function.fsockopen]:无法连接到 https://example.com/soapserver.php:443 (无法找到套接字传输“https” - 您是否忘记启用它当你配置PHP时?)在C:\ Home等等等......
我正在使用IIS服务器顺便说一句,(不,这不是我做的!)所以我认为这与没有开放有关ssl,但我不确定。 有人可以帮忙吗?
我做了一个 phpinfo() 并且我有 ssl,但在 IMAP 和 cURL 上,仅此而已。
有任何想法吗?
I'm using this to check for the availability of a URL:
$fp = fsockopen($url, 443, $errno, $errstr);
and I get this error back...
Warning: fsockopen() [function.fsockopen]: unable to connect to https://example.com/soapserver.php:443 (Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?) in C:\Home etc etc....
I'm using an IIS server btw,( no its not my doing! ) so I think its something to do with not having open-ssl, but I'm not sure. Can anyone help please?
I did a phpinfo() and I do have ssl, but on IMAP and cURL, thats all.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
取消注释行:
php.ini
中的extension=php_openssl.dll
Uncomment the line:
extension=php_openssl.dll
inphp.ini
您应该在 fsockopen 调用中仅使用主机名,而不是 URL。 您需要提供 uri,减去实际 HTTP 标头中的主机/端口。 正如 @Martijin 所指出的,以及手册页中列出的,您需要在主机名前面加上 ssl://(用于 SSL)或 tls://(如果使用传输层安全性)。
fsockopen 手册页。 看看例子#1。
You should be using just the hostname, not the URL in the fsockopen call. You'll need to provide the uri, minus the host/port in the actual HTTP headers. As @Martijin noted, and as listed in the manual page, you'll need to preface your host name with ssl:// for SSL or tls:// if using transport layer security.
Manual page for fsockopen. Look at Example #1.
同样对于 ssl,您需要在主机前添加 ssl:// 前缀
also for ssl you need to prefix the host with ssl://
假设您想获取强制执行 HTTPS 的《纽约时报》:
错误:
$client = stream_socket_client('https://www.nytimes.com', $errno, $errstr, 30);
正确:
$client = stream_socket_client('tcp://www.nytimes.com:443', $errno, $errstr, 30);
注意我已经替换了
https://
与tcp://
并将 443 端口附加到主机名。我想我们可以说
stream_socket_client()
不会讲 URL。Let's say you wanted to grab NY Times, which enforces HTTPS:
Incorrect:
$client = stream_socket_client('https://www.nytimes.com', $errno, $errstr, 30);
Correct:
$client = stream_socket_client('tcp://www.nytimes.com:443', $errno, $errstr, 30);
Note I've replaced
https://
withtcp://
and appended the 443 port to the hostname.I guess we can say that
stream_socket_client()
does not speak URLs.切换到
ssl://
对我有用,但我不断收到 BAD REQUEST 响应。 我发现我需要再添加一行来显式声明我的主机标头,如所述 此处并确保我已将 HTTP 从HTTP/1.0
更新为HTTP/1.1
:Switching to
ssl://
worked for me but I kept getting a BAD REQUEST response. I found that I needed to add one more line to declare explicitly my Host Header as described here and ensure that I've updated my HTTP fromHTTP/1.0
toHTTP/1.1
:检查 php 是否安装了curl。
如果未安装,请安装curl。
对于 Windows 取消注释行:extension=php_openssl.dll 在 php.ini 中,
对于 ubuntu sudo apt-get install php-curl
Check curl installed or not for php.
if it is not installed install the curl.
for windows Uncomment the line: extension=php_openssl.dll in php.ini,
for ubuntu sudo apt-get install php-curl