简体   繁体   English

AWS API网关返回400错误请求,但Postman正常工作

[英]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. 我正在使用SendGrid Parse API( https://sendgrid.com/blog/parse-webhook-tutorial/ )将传入的电子邮件正文过帐到AWS API Gateway。

When I send the webhook to requestb.in I get the responses fine. 当我将webhook发送到requestb.in时,我得到的响应很好。

When I use Postman to fake a request to my server I get a proper response. 当我使用Postman伪造对服务器的请求时,我得到了正确的响应。

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). 但是,当我告诉SendGrid将Webhook发送到我的服务器时,我收到来自SendGrid的400错误响应错误,并且我的服务器再也没有命中(因此,我认为API网关抛出了错误)。

Is there something simple I'm missing? 有什么简单的我想念的吗? I tried setting up CORS but that wasn't it (or I set it up wrong). 我尝试设置CORS,但不是(或者我设置错了)。

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. 我刚刚调试了一个API网关问题,该问题引发了与CORS相关的错误消息,并且该请求从未到达我的服务器,但真正的问题是来自请求中的数据。

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. 因此我发现,如果请求存在任何问题,API网关将抛出默认的400错误,表明没有Allow-Access-Control-Origin标头。 This can make you believe you have an issue with your CORS. 这可以使您认为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. 如果您设置MOCK GET请求,在浏览器中发出请求,并在浏览器开发人员工具的“网络”标签中确认它返回200,则可以消除CORS的问题。

Once I knew it was coming from only the POST requests it had to be an issue with the data. 一旦我知道它仅来自POST请求,就必然是数据问题。 I was sending a JSON hash without stringifying it. 我发送的JSON哈希值未经过字符串化处理。 So the solution was to use JSON.stringify(request_data) . 因此解决方案是使用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. 如果您将请求和回答添加到您的问题中,我也许可以提供进一步的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sendgrid与SAPUI5应用程序的集成在POST上返回“ 400 Bad Request”,但在Postman上有效 - Sendgrid integration with SAPUI5 app returns '400 Bad Request' on POST but works on Postman Sharepoint REST api 返回错误请求 (400) - Sharepoint REST api returns Bad Request (400) Firebase 动态链接 REST API 返回 400 错误请求 - Firebase dynamic links REST API returns 400 bad request fetch 返回 400 个错误的请求 - fetch returns 400 bad request 对Flickr API的AJAX请求返回0个结果,但可与curl / postman一起使用 - AJAX request to Flickr API returns 0 results, but works with curl/postman XMLHttpRequest 从 java 脚本调用时返回错误请求 (400),如果我从 Java 或 Postman 客户端调用它工作正常 - XMLHttpRequest Returning Bad Request (400) while calling from java script , if i am calling from Java or Postman client it working fine Api 发布 400 错误请求 - Api Post 400 Bad Request Aws Api 网关/Lambda python dynamodb 适用于 postman 但不适用于网页 - Aws Api gateway/Lambda python dynamodb works with postman but doesn't with webpage API 在 postman 中工作正常,但在反应的前端部分中却没有 - API works fine in postman but not in frontend part of react 通过预先签名的 url 上传 AWS S3 返回 400 错误请求 - AWS S3 upload via presigned url returns 400 bad request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM