从POST请求咕噜连接代理插件不包含数据 [英] POST requests from grunt-connect-proxy plugin do not contain data

查看:118
本文介绍了从POST请求咕噜连接代理插件不包含数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它的工作原理至今的角度可以使一个POST请求到我的本地运行Apache服务器。从该服务器,我返回一个Symfony的JsonResponse对象:

It works so far that Angular can make a POST request to my local running Apache server. From that server, I return a Symfony JsonResponse object:

$http.post("/api", {"foo":"bar"})
          .success(function(data, status, headers, config) {
              $scope.data = data;
              console.log(data);
          }).error(function(data, status, headers, config) {
              $scope.status = status;
          });

现在我坚持的事实,它只返回 [] 。如果我回到硬codeD关联数组,它的工作原理。

Now I am stuck with the fact that it only returns []. If I return a hardcoded associative array, it works.

这可能是什么问题呢? (插件

What could be the problem? (plugin)

推荐答案

好吧,解决办法是检查 CONTENT_TYPE:应用程序/ JSON 因为$ _ POST不会得到如果它被设置填充。
角全自动做到这一点。

Ok, the solution was to check for content_type:application/json because the $_POST will not get populated if it is set. Angular automaticly does this.

如果你不知道这一点,它正在寻找在大海捞针。
在这方面,<一href=\"http://stackoverflow.com/questions/11442632/how-can-i-make-angular-js-post-data-as-form-data-instead-of-a-request-payload?rq=1\">this帖子是非常有益的。并按照我无意中发现了此页面

If you don't know this, it is looking for a needle in a haystack. In that regard, this post was extremely helpfull. and following that I stumbled on this page

这行做了

if(0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/json')){

这篇关于从POST请求咕噜连接代理插件不包含数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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