简体   繁体   中英

AWS API gateway returns 400 Bad Request, but Postman works fine

I am using the SendGrid Parse API ( https://sendgrid.com/blog/parse-webhook-tutorial/ ) to get incoming email bodies POSTed to an AWS API Gateway.

When I send the webhook to requestb.in I get the responses fine.

When I use Postman to fake a request to my server I get a proper response.

When I tell SendGrid to send the webhook to my server, however, I get a 400 Bad Response error from SendGrid and my server never gets hit (so I assume the API Gateway is throwing the error).

Is there something simple I'm missing? I tried setting up CORS but that wasn't it (or I set it up wrong).

I'm stumped.

Thanks!

I just debugged an API Gateway issue that was throwing an error message related to CORS and the request was never hitting my server, but the real issue was stemming from the data in the request.

So I have found out that if there is any issue with a request API Gateway will throw a default 400 error saying there was no Allow-Access-Control-Origin header. This can make you believe you have an issue with your CORS. You can eliminate CORS as an issue if you set up a MOCK GET request, make the request in the browser, and verify it returns 200 in the network tab in the browser developer tools.

Once I knew it was coming from only the POST requests it had to be an issue with the data. I was sending a JSON hash without stringifying it. So the solution was to use JSON.stringify(request_data) .

I would check the data format of the requests. If you add the requests and responses to your question I might be able to help further.

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