Php API-连接是否安全?

Php API-连接是否安全?,php,api,Php,Api,如何检查与REST API的连接是否安全 1) 我正在构建一个API,希望在生成响应并返回到客户端之前确保连接正在运行SSL。。在每个请求中都传递用户名和密码 2) 如何使用SSL建立fsockopen连接 $this->url = 'api.domain.com'; $this->path = '/v1/json/account/user/pass/?id=123'; if($this->fp = fsockopen($this->url, $this->por

如何检查与REST API的连接是否安全

1) 我正在构建一个API,希望在生成响应并返回到客户端之前确保连接正在运行SSL。。在每个请求中都传递用户名和密码

2) 如何使用SSL建立fsockopen连接

$this->url = 'api.domain.com';
$this->path = '/v1/json/account/user/pass/?id=123';

if($this->fp = fsockopen($this->url, $this->port, $errno, $errstr, $this->timeout)){
    $write = "$this->method $this->path HTTP/1.1\r\n";
    $write .= "Host: $this->url\r\n";
    $write .= "Content-Type: $this->content_type\r\n";
    $write .= "Connection: Close\r\n\r\n";

    fwrite($this->fp, $write);

    while($line = fgets($this->fp)){
        if($line !== false) $this->response .= $line;
    }

    fclose($this->fp);
}

只需检查
$\u服务器['HTTPS']

网站上的PHP手册说:

“HTTPS”

如果通过HTTPS协议查询脚本,则设置为非空值

注意:请注意,当将ISAPI与IIS一起使用时,如果请求不是通过HTTPS协议>发出的,则该值将关闭


你当然可以。你甚至可以强迫它。HTTP在端口80上工作,HTTPS在443上工作。您可以放弃443中所有未提交的流量。

好吧,什么样的API?你是如何连接到它的?请为问题添加更多详细信息。如何使用fsockopen建立SSL连接?