dimanche 2 octobre 2016

Angular limit for POST array of params

I am trying to pass an array of large objects (10 objects) from Angular app to my Laravel API to process. The params I'm passing are as such:

enter image description here

I'm getting the following lengthy error which shows all the objects passed:

enter image description here

...

enter image description here

At the bottom of that last image you'll see the error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://dde.localhost' is therefore not allowed access. The response had HTTP status code 414

Code 414, as defined here, is Request URI too long. I originally received this error when using GET and passing a serialized string. I'm using POST now and sending a payload. Why does this error persist?

They recommend:

Typically Web servers set fairly generous limits on length for genuine URLs e.g. up to 2048 or 4096 characters. If your URL is particularly long, you can usually try shorter variations to see roughly where the limit is.

Obviously I cannot shrink the data I'm sending as all of it needs to be analyzed. How can I properly package this data to send as a payload?

Here is my Angular $http request:

        getQuestionAnswers: function(params) {
            console.log('params', params);
            return Token.refreshToken().then(function () {
                return $http({
                    method: 'POST',
                    url: url + ver + '/questions/checkMany',
                    params: {
                        'questions[]' : params
                    },
                    headers: Auth.getOAuthHeader(),
                    cache: true
                });
            });
        },

I thought it may have to do with POSTing a large amount of data (GET has yelled at me before for the URI being to long), so I stringified and sent as JSON with the same issue:

var stringified = JSON.stringify(params);
...
params: {
    'questions[]' : stringified
},

Laravel route:

$router->post('/questions/checkMany', 'Resources\Questions@getAnswers');

I am tailing my laravel API, $ tail -f laravel-2016-10-02.log, and there are no errors there. This is an OPTIONS issue so I would assume it'd be on the client side.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire