我在家庭控制器中使用代码:
public function myAction1(Request $request)
{
$request->session()->put('redirect', $_POST['redirect']);
}
public function myAction2(Request $request)
{
$request->session()->get('redirect');
}
这是我route
的一部分:
Route::get('pGetway/send', 'HomeController@myAction1')->middleware('cors');
Route::post('pGetway/send', 'HomeController@myAction1')->middleware('cors');
Route::get('pGetway/verify', 'HomeController@myAction2')->middleware('cors');
Route::post('pGetway/verify', 'HomeController@myAction2')->middleware('cors');
当我使用来自session
的浏览器的HTTP请求时工作得很好但是当通过curl
从其他网站发送数据时它不起作用意味着会话未设置!!
我想要设置sesstion并使用其他操作中的内容,例如myAction2
这是curl请求帖子:
$params = ['redirect'=>'http://example.com'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost:8000/pGetway/send");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
$response = curl_exec($ch);
curl_close($ch);
由于
答案 0 :(得分:0)
you should set curl cookies file and cookies jar to use it with session
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');