參考面網址
http://twpug.net/modules/smartfaq/faq.php?faqid=8
$curl = curl_init("https://localhost/test.php);
這行有點小錯誤, 應該是
$curl = curl_init("https://localhost/test.php");
代碼:
$PostData = "foo=abc&bar=def";
$curl = curl_init("https://10.3.0.34/a3.php");
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); //這行請參考 http://curl.haxx.se 的介紹
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //這行請參考 http://curl.haxx.se 的介紹
//設定伺服器憑證,要不要像我忘了... 請自己 try 一下
//curl_setopt($curl, CURLOPT_CAPATH, "/certificate");
//curl_setopt($curl, CURLOPT_CAINFO, "/certificate/server.crt");
//不直接顯示回傳結果
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//post資料給指定網頁
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $PostData);
$Result = curl_exec($curl);
curl_close($curl);
?>
資料送出
-----
1. 開啟 php_openssl
2. 範例 fsockopen()
代碼:
$set_userid = "admin";
$set_passwd = "123456";
$POST_VALUES = "my_userid=" . $set_userid . "&my_passwd=" . $set_passwd;
$fp = fsockopen("ssl://192.168.0.1", 443, $errno, $errstr, 30);
if ($fp){
$out = "";
$out .= "POST /my_service/login.php HTTP/1.1\r\n";
$out .= "Host: 192.168.0.1\r\n";
$out .= "Accept: text/html\r\n";
$out .= "Connection: close\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-length: " . strlen($POST_VALUES) . "\r\n";
$out .= "\r\n";
$out .= ($POST_VALUES) . "\r\n";
fputs($fp, $out);
while (!feof($fp)){
$log .= fgets($fp, 1024);
}
fclose($fp);
}
echo $log;
來源: http://forum.icst.org.tw/phpbb/viewtopic.php?t=10151