修身,邮差和AngularJs:$ APP-GT&;&请求 - GT; getBody()VS $ APP-GT&;&请求 - GT;后() [英] Slim, Postman and AngularJs : $app->request->getBody() vs $app->request->post()

查看:166
本文介绍了修身,邮差和AngularJs:$ APP-GT&;&请求 - GT; getBody()VS $ APP-GT&;&请求 - GT;后()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是个初学者。我已经写在客户端和服务器端的PHP API做出了AngularJs GUI的测试应用程序。

I'm a beginner. I've written a test application made of an AngularJs GUI on the client side and a PHP API on the server side.

这是角处理服务请求

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'},
    });

}]);

当我从应用角度提出了一本书,我可以通过捕捉修身POST

When I submit a book from the Angular app I can catch the POST in Slim by using

$post_a = json_decode($app->request->getBody());
//$post_b = $app->request->post(); //this would be empty

当我使用邮递员,我执行POST我可以使用捕捉修身POST

When I use Postman and I perform a POST I can catch the POST in Slim by using

//$post_a = json_decode($app->request->getBody()); // this would be empty
$post_b = $app->request->post();

我不明白为什么会存在这种差异。能否请您解释一下吗?

I don't get why there is this difference. Could you please explain?

难道我不是要赶上后只需用$ APP->请求 - >后();在这两种情况下?为什么从角来后只能被抓$ APP->请求 - > getBody()?

Am I not meant to catch the post just with $app->request->post(); in both the cases? Why the post coming from Angular can be caught only with $app->request->getBody()?

推荐答案

$ APP->提交后()方法检索键/值数据;请求 - &GT在应用程序/ x-WWW的形式urlen codeD 请求。如果请求使用不同的内容类型(例如:应用程序/ JSON ),你可以检索与 $ APP-&GT的原始请求主体;要求 - > getBody()法和德code这是必要的。让我知道,如果你还有其他问题。

The $app->request->post() method retrieves key/value data submitted in a application/x-www-form-urlencoded request. If the request uses a different content-type (e.g. application/json), you can retrieve the raw request body with the $app->request->getBody() method and decode it as necessary. Let me know if you have further questions.

这篇关于修身,邮差和AngularJs:$ APP-GT&;&请求 - GT; getBody()VS $ APP-GT&;&请求 - GT;后()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆