POST requests from grunt-connect-proxy do not contain data

It works so far that Angular can make a POST request on my local Apache server. From this 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; }); 

Now I'm stuck in that it only returns [] . If I return a hard-coded associative array, it works.

What could be the problem? ( plugin )

0
source share
2 answers

Well, the solution was to check for content_type:application/json , because $ _POST will not populate if it is set. Angular does this automatically.

If you do not know this, he is looking for a needle in a haystack. In this regard, this post has been extremely helpful. and after that I came across on this page

this line did it

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

If you get [] as success data, it means your server is giving an empty response, which still remains a valid response. Try running the API in a browser (or better use the POSTMAN plugin in Chrome) to check if the same API call [] returns as an answer.

+2
source

All Articles