0

I am sending a post request with $http:

$http({
    method: 'Post',
    url: urlBuilt,        
    headers: {'Content-Type': 'application/json'},                                                         
    params: {"colCode":modCodeCol,"whereClause":clause}
});

When the where clause is very huge, I am getting bad request 400 error. When the where clause contains a small string it works. How can we fix this.

1
  • coud you share an example of data to whereClause ??? Commented Aug 14, 2017 at 21:47

2 Answers 2

1

Try change params to data in the block of http like this.

$http({
    method: 'POST',
    url: urlBuilt,        
    headers: {'Content-Type': 'application/json'},                                                         
    data:{"colCode":modCodeCol,"whereClause":clause}
});

params if for queryParams it mean it send on the url. data appends to the request body.

Sign up to request clarification or add additional context in comments.

1 Comment

@Carrasco, I used data, and in my spring contoller I have changed requestParam to requestBody like below,the request sent by the client was syntactically incorrect
0

for POST request you need to send data as JSON also it's better to Get a promise and resolve it after send the request like this :

  var data = {
               "colCode":modCodeCol,
               "whereClause":clause 
             }
  $http({ url: urlBuilt , method: 'POST', data: data })
        .then(function (result) {
            deferred.resolve({ data: result.data.Data, count: result.data.Count });

        });

2 Comments

I just want to know why need use $q in here? And you can use short syntax of http . $http.post(urlBuld,data).then(...)
no one used $q anywhere here! $q used when you want have bulk requests

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.