gpt4 book ai didi

php - 使用 Curl 在 Https 服务器 (PHP) 中发布数据

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:24 25 4
gpt4 key购买 nike

我试图在 php 中使用 Curl 访问 https 服务器的 api。我不知道为什么我无法访问它并且我得到 null 作为响应。

我的基本代码是这样的,

<?php

$url = "https://my_website";
$data = array(
'groupName' => 'Test',
'units' => 1,
'principalEmail' => 'todd.bailey+onboard@rentmoola.com',
'principalFirstName' => 'Todd',
'principalLastName' => 'Bailey',
'principalPhone' => 1212,
'principalSSN' => 2121,
);

$jsonStringPOST = json_encode($data);
$login = array('username'=>'some_user_name','password'=>'some_password');
$headers = array('Accept: application/json','Content-Type: application/json');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //for solving certificate issue
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERPWD, $login['username'] . ':' . $login['password']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStringPOST);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$resultPOST = curl_exec($ch);

if($resultPOST === false)
{
var_dump('Curl error: ' . curl_error($ch));

}

?>

我得到的错误是这样的:

'Curl error: error: 1408D13A:SSL routines: SSL3_GET_KEY_EXCHANGE:unable to find ecdh parameters.

好吧,当我尝试通过 Chrome 的 POSTMAN 应用程序将数据发布到服务器时,我能够得到响应。我无法在 php 中使用 CURL 找到解决此问题的方法。任何建议或答案将不胜感激。

谢谢。

最佳答案

您可以 download cacert.pem from here - 保存到您的网站,在根目录之外。

在 curl 请求中,您可以执行以下操作:

$cacert=realpath('/path/to/cacert.pem');
curl_setopt( $ch, CURLOPT_CAINFO, $cacert );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 1 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );

curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla-da-gorilla' );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );

关于php - 使用 Curl 在 Https 服务器 (PHP) 中发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34329398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com