php - 我可以使用 ssl ://and https://in an URL interchangeably? 吗

标签 php http url post request

我必须编写一些 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/

相关文章:

python - Django url 关键字

php - 无法在 PHP 中加载 LDAP 函数

HTTP 405——网络服务器合规性

objective-c - 如何在 iOS Facebook 应用程序上加载 Facebook 页面链接

http - 谷歌云存储返回旧数据

file - 使用 HTTP POST 将文件发送到 IIS 7.5 虚拟目录

java - 在Java中打开URL获取内容

php - 用php替换字符串中的所有其他字符

php - Composer 找不到私有(private)托管的包

javascript - 检查用户是否在 PHP 中关闭了页面?