loalhost to aws EC2, GET request works but POST request not working

1

Hello, I created one node js app with an express server and further I dockerize it and deployed it on ECS. When I hit from localhost to that EC2 public IP then the GET request works but when I am trying a POST request from localhost to that EC2 it gives an error of "Connection Refused" and in security groups, all traffic rules is enabled. Where is the issue, can someone guide me? Thanks

質問済み 1年前242ビュー
1回答
2

Usually If the GET request work, POST request should work too. You can follow the below steps to diagnose and fix this issue:

Step 1: Troubleshoot the code to understand the difference in functioning of your GET and POST request.

Step 2: Check the status of your POST request, is it 200 or something else?(it should be 200 ideally because connection is intact as mentioned in the aforementioned question that GET request are already working) Step 3: Check if you have added CORS header in your NodeJS backend application code.

Step 4: Check if you have written your CORS code inside app.post() function inside of app.js on node.js server? (If yes then, you need to move the cors code at the top of the app.js node.js server file. and that will fix the issue and your POST request will also work as expected)

回答済み 10ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ