如何使file_get_content()與HTTPS一起工作?我正在設置信用卡處理,并需要使用一個解決辦法的卷曲。當我使用測試服務器(它沒有調用SSL URL)時,下面的代碼運行良好,但是現(xiàn)在當我使用HTTPS在工作服務器上測試它時,它失敗了,錯誤消息“未能打開流”。function send($packet, $url) {
$ctx = stream_context_create(
array(
'http'=>array(
'header'=>"Content-type: application/x-www-form-urlencoded",
'method'=>'POST',
'content'=>$packet )
)
);
return file_get_contents($url, 0, $ctx);}
3 回答

溫溫醬
TA貢獻1752條經驗 獲得超4個贊
$w = stream_get_wrappers();echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n";echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";echo 'wrappers: ', var_export($w);
openssl: yes http wrapper: yes https wrapper: yes wrappers: array(11) { [...]}

浮云間
TA貢獻1829條經驗 獲得超4個贊
這個 php_openssl
必須存在并啟用擴展。 allow_url_fopen
必須設置為 on
extension=php_openssl.dll allow_url_fopen = On

冉冉說
TA貢獻1877條經驗 獲得超1個贊
function getSslPage($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); curl_close($ch); return $result;}
注意:這將禁用ssl驗證,這意味著 HTTPS提供的安全性丟失了。..只使用此代碼進行測試/本地開發(fā), 從不上網或者其他面向公眾的網絡。如果此代碼有效,則意味著SSL證書不受信任或無法驗證,您應該將其作為一個單獨的問題加以解決。
- 3 回答
- 0 關注
- 813 瀏覽
添加回答
舉報
0/150
提交
取消