使用Curl Post的Laravel TokenMismatchException

时间:2015-07-07 14:59:50

标签: laravel token mismatch

有人可以帮助解决这个令牌问题吗? 我想我在标题和输入帖子字段中设置了令牌正确

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");


$url = 'http://------My url------/';

foreach ($_POST as $k => $v){
    $fields[$k] = $v;
}

// build the urlencoded data
$postvars = http_build_query($fields);

// open connection
$ch = curl_init();

$headers[] = 'X-CSRF-TOKEN:'.$fields['_token'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);

// execute post
$result = curl_exec($ch);

print_r($result);
// close connection
curl_close($ch)

enter image description here

0 个答案:

没有答案