我必须编写一些 PHP 代码来向外部服务器发出发布请求,并从服务器所有者那里得到了两个不同的示例,一个在 URL 中使用“ssl://”,另一个使用“https://”。
它们可以互换使用吗?这将记录在哪里?谢谢!
编辑以包含 PHP 代码(不知道为什么我不能正确格式化代码,如果有人可以帮助解释如何将初始注释合并到代码块中):
// make a http post request to an external server
function httpPost($host, $usepath, $postdata = "") {
$fp = fsockopen($host, 443, $errno, $errstr, 60);
if( !$fp ) {
print "$errstr ($errno)<br>\n";
}
else {
fwrite( $fp, "POST $usepath HTTP/1.0\n");
$strlength = strlen( $postdata );
fwrite( $fp, "Content-type: application/x-www-form-urlencoded\n" );
fwrite( $fp, "Content-length: ".$strlength."\n\n" );
fwrite( $fp, $postdata."\n\n" );
$output = "";
while( !feof( $fp ) ) {
$output .= fgets( $fp, 1024);
}
fclose( $fp);
}
return $output;
}
最佳答案
ssl://
URLs 是 PHP 特有的。这是 PHP 在使用其 fsocketopen
函数时提供使用直接 SSL/TLS 连接的方式。参见 List of Supported Socket Transports in the manual .
ssl://
将为您提供一个 SSL/TLS 连接,上面没有任何应用程序协议(protocol):这将取决于您的应用程序来实现您需要的通信协议(protocol)。
相比之下,https://
将通过此 SSL/TLS 连接实现 HTTP 协议(protocol)。
请注意 default settings for ssl://
and tls://
are rather poor in terms of security .特别是,verify_peer
的默认值为 false,这会使连接容易受到 MITM 攻击。
关于php - 我可以使用 ssl ://and https://in an URL interchangeably? 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23493950/