php - 使用 curl 将会话值传递给另一个项目,并以 "{"abc@gmail_com":null}" 这种格式接收该值
问题描述
在我的项目中第一次使用 curl。我在我的项目中使用了会话。当我这样做时,{{ 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();
}
请帮帮我。
注意:我没有在这个项目中使用工匠服务,所以我的网址很好。
解决方案
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]);
推荐阅读
- r - 我可以使用什么 R 代码将列分成两部分?
- jquery - 如何将两个ajax函数合二为一?所以,我可以同时传递链接中的两个变量
- flutter - Flutter Bloc 从不同的小部件更改状态
- prolog - Prolog - 转换为尾递归
- swift - SwiftUI 使用 Timer 每 60 秒发布一次 API 数据
- codenameone - 模拟器因 BrowserComponent 而死机
- javascript - 即使设置了onClick,按钮也无法点击?
- ios - 如何处理 App Store Connect 中的“App Preview is too large”错误?
- wordpress - 我的页面使用的是我的 Index.php 而不是我的 page.php
- apache - 如何使用 apache 连接到本地 PC?