我正在建立一个定制的电子商务解决方案,我使用的支付系统要求我发送HTTPS帖子。
我如何使用php (和CURL)来完成这个任务,这与发送http帖子有什么不同吗?
更新:
谢谢你的答复,它们非常有用。我想我需要购买SSL证书才能工作,显然我会为最终的站点购买SSL证书,但是有什么方法可以让我在不购买SSL证书的情况下测试它呢?
谢谢你,妮可
发布于 2009-07-20 15:28:30
PHP/Curl将很好地处理https请求。您可能需要做的是关闭CURLOPT_SSL_VERIFYPEER,特别是在针对dev服务器的情况下。这是因为dev服务器可能是自签名的,并且无法通过验证测试。
$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);发布于 2009-07-20 15:34:27
您还可以使用流api和http/https上下文选项。
$postdata = http_build_query(
array(
'FieldX' => '1234',
'FieldY' => 'yaddayadda'
)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://example.com', false, $context);您仍然需要一个提供SSL加密的扩展。可以是php_openssl,也可以是(如果是那样编译的话) php_curl。
发布于 2009-07-20 15:22:55
不,没有太大的区别。卷发自己做一切必要的事。
请参阅参考页中的示例。
https://stackoverflow.com/questions/1154172
复制相似问题