在我的项目中第一次使用curl。我在我的项目中使用了session。当我执行{{ dd(session()->all()) }}
时,我会得到"email" => "abc@gmail.com"
所需的结果
但是,当我通过curl将这个变量传递给我的另一个项目时,收到的值的格式是"{"abc@gmail_com":null}"
.com更改为_com,并且存在空值
因此,我无法从数据库中提取该电子邮件地址的记录。以下是我的代码:
$sendData = Session::get('email');
// dd($sendData);
$url = 'http://localhost/myproject/project-apis/public/index.php/myRequest';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$sendData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
// dd($server_output);
$dataReceive = json_decode($server_output);
if($dataReceive->status == 'TRUE'){
$profile = $dataReceive->profile;
}
else{
$profile = array();
}
请帮帮我。
注意:我没有在这个项目中使用工匠服务,所以我的网址是好的。
发布于 2019-07-08 21:48:25
CURLOPT_POSTFIELDS
需要数组或urlencoded编码的字符串:
https://www.php.net/manual/en/function.curl-setopt.php
但此行仅存储$sendData
中的电子邮件地址
$sendData = Session::get('email');
试着像这样设置CURLOPT_POSTFIELDS
:
curl_setopt($ch, CURLOPT_POSTFIELDS, ['email' => $sendData]);
https://stackoverflow.com/questions/56942537
复制相似问题