我在客户端有 Angular ,在后端有 Laravel。当我尝试使用 input::get('params.id') 访问发送到 laravel 的参数时,我得到 null: 客户端发布请求:
$http.defaults.headers.post = {'X-CSRF-Token':token};
$http.post('/projectx/public/provider/products/remove/'+PID,{
params:{
id:$scope.products[index].id,
title:$scope.products[index].title,
price:$scope.products[index].price
}
}).success(function(response){
if(response.status){
UI.simpleNotify('Product removed!','success');
}else{
console.log(response);
UI.simpleNotify('Error removing product!','error');
}
}).error(function(){
UI.connectionError();
});
这是 Laravel 后端代码:
$productId = Input::get('params.productId');
我尝试过输入::all();但它返回 null。
但是当我删除 Angular 代码上的http自定义 header (“X-CSRF-Token”)时,它工作正常。
那么您认为问题出在哪里? 提前致谢。
最佳答案
对于 post 和 put 请求,您不应将默认的 post header 设置为对象文字。
$http.defaults.headers.post['X-CSRF-Token'] = token;
关于php - 当自定义 http header 设置为 post 请求时,Laravel Input::get ('params.id' ) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23674304/