2011-07-01 105 views
1

如何檢查與REST API的連接是否安全?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); 
} 
+0

那麼,什麼樣的API?你如何連接到它?請在問題中添加更多細節。 – Piskvor

+0

如何與fsockopen進行SSL連接? – clarkk

回答

2

只要勾選$_SERVER['HTTPS']

PHP手冊在http://php.net/manual/en/reserved.variables.server.php說:

'HTTPS'

設置爲如果腳本是通過HTTPS協議查詢一個非空值。

注意:請注意,在IIS中使用ISAPI時,如果未通過HTTPS協議進行請求,則該值將被關閉。

0

當然可以。你甚至可以強迫它。 HTTP在端口80上工作,在443上運行HTTPS。你可以丟棄所有不在443上的通信。