在我的驗收測試,我試圖發送一個JSON請求有一個cookie:如何通過標頭設置cookie?
// CartTest.php
$response = $this->postJson(route('carts.store'), [], [
'Cookie' => 'uuid='.Crypt::encrypt($cart->uuid)
]);
當我在控制器裏做$request->hasCookie('uuid')
,我得到false
。
我也嘗試了不同的變化,如Set-Cookie
,HTTP_SET_COOKIE
等,但沒有一個似乎工作。爲了簡潔起見,我寧願傳遞postJson
而不是通用的call
。
任何想法?謝謝
您是否嘗試過HTTP_COOKIE? –