1
votes

I'm trying to send a POST request to a REST service via AWS API Gateway.

The content-type of the request should be 'application/x-www-form-urlencoded'. It's an authentication service that I'm trying to access. I'm sending 'username' and 'password' in my request body.

When I send the the request via Postman, it works ( It's giving me the proper response ).

But I want to create an API from the API Gateway to access this endpoint.

When I create a POST method in the API Gateway and try to test it without specifying any content-type, the back-end server tells me to send the request by using the content-type 'application/x-www-form-urlencoded'.

Then when I try to put the content-type in 'Mapping Template' section in the 'Integration Request' of the API, the request doesn't even hit the backend. There's an error ( a JSON response ) comes when I test it, saying 'Unsupported Media Type'.

Does anyone out here knows any workaround for this?

1
What do you mean by "I want to create an API from the API Gateway to access this endpoint"? - Munavir Chavody

1 Answers

1
votes

I found the solution.

In order to access a POST service using the content-type ‘application/x-www-form-urlencoded’ in API Gateway, make sure you are doing the following in the API console.

Make sure you have enabled the ‘Use HTTP Proxy integration’ as the following in the ‘Integration Request’ section.

enter image description here

When you test the request, make sure you are putting the content type ‘application/x-www-form-urlencoded’ inside the Header’s box as in the following.

enter image description here

And the request body should be like the following as well.

[email protected]&password=123456