【发布时间】:2016-09-01 14:38:38
【问题描述】:
我是初学者。我编写了一个测试应用程序,由客户端的 AngularJs GUI 和服务器端的 PHP API 组成。
这是处理请求的角度服务
myApp.factory('Book', ['$resource', 'API_URL', function($resource, API_URL){
return $resource(API_URL + '/books/:bookId', {bookId: '@bookId'}, {
get: { method: 'GET', isArray:true },
update: { method: 'PUT'},
save: { method: 'POST'},
delete: {method:'DELETE'},
});
}]);
当我从 Angular 应用程序提交一本书时,我可以使用 Slim 捕捉 POST
$post_a = json_decode($app->request->getBody());
//$post_b = $app->request->post(); //this would be empty
当我使用 Postman 并执行 POST 时,我可以使用
在 Slim 中捕获 POST//$post_a = json_decode($app->request->getBody()); // this would be empty
$post_b = $app->request->post();
我不明白为什么会有这种差异。你能解释一下吗?
我不是打算只用 $app->request->post();在这两种情况下?为什么来自 Angular 的帖子只能用 $app->request->getBody() 捕获?
【问题讨论】:
标签: angularjs rest slim postman