問題描述
我正在設置自定義電子商務解決方案,我使用的支付系統要求我發送 HTTPS POSTS.
I'm setting up a custom e-commerce solution, and the payment system I'm using requires me to send HTTPS POSTS.
我如何使用 php(和 CURL?)執行此操作,這與發送 http 帖子有什么不同嗎?
How can I do this using php (and CURL?), is it any different from sending http posts?
更新:
感謝您的回復,他們非常有用.我假設我需要購買 SSL 證書才能使其工作,而且我顯然會為最終站點執行此操作,但是有什么方法可以讓我在不購買的情況下對其進行測試?
Thanks for your replies, they've been very useful. I assume I will need to purchase an SSL certificate for this to work, and I will obviously do this for the final site, but is there any way for me to test this without buying one?
謝謝尼科
推薦答案
PHP/Curl 會很好地處理 https 請求.您可能需要做的是,尤其是在針對開發服務器時,關閉 CURLOPT_SSL_VERIFYPEER.這是因為開發服務器可能是自簽名的并且無法通過驗證測試.
PHP/Curl will handle the https request just fine. What you may need to do, especially when going against a dev server, is turn CURLOPT_SSL_VERIFYPEER off. This is because a dev server may be self signed and fail the verify test.
$postfields = array('field1'=>'value1', 'field2'=>'value2');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://foo.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
// Edit: prior variable $postFields should be $postfields;
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // On dev server only!
$result = curl_exec($ch);
這篇關于如何使用 php 發送 HTTPS 帖子的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!