简体   繁体   中英

Angular $resource POST request query params not detected by AWS API Gateway?

I'm testing out AWS's API Gateway and I can't get it to read a query string parameter included in POST requests from Angular.

However, AWS's API Gateway DOES detect the query string param when I use cURL, so this must be an Angular issue. Am I missing a Header or something?

FYI, I have set up template mapping correctly on the API Gateway, so that is not the issue.

https://cabvt12afasf4.execute-api.us-east-1.amazonaws.com/resource?access_token=1234112313123

resourceCreate: {
        method: 'POST',
        isArray: false,
        params: {
            access_token: access_token
        },
        url: 'https://cabvtj3br4.execute-api.us-east-1.amazonaws.com/resource'
    },

The problem was this:

Angular sets the Content-Type header to application/json;charset=UTF-8 and this was breaking the AWS API Gateway.

Switching Content-Type to application/json in my Angular $resource solved the problem.

createResource: {
        method: 'POST',
        isArray: false,
        headers: {
            'Content-Type': 'application/json'
        },
        url: 'http://www.resource.com/create'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM