danabaillie
danabaillie

Reputation: 75

Server App on Heroku is not accessibe

Hi we have a Ruby on Rails server application on Heroku, but when I send a post request to it, I always get a 400 Bad Request response. I have searched other 400 errors, but none are related to our issue. The HTTP response that we receive looks like this below:

HTTP/1.1 400 Bad Request

Server: Cowboy

Date: Fri, 14 Aug 2015 21:55:25 GMT

Content-Length: 0

The post request that I am sending looks like this below:

POST http://ourapp.herokuapp.com/api/v1/requests HTTP/1.0

Accept-Language: en-us

Accept: text/plain

Content-Type: application/x-www-form-urlencoded

Content-Length: 38

Connection: Close

request=600&key=&newKey=danasecretkey&

Sorry, I had to put blank lines after each header or it would all show up on one line.

If I create an HTML form to send the data, there is no issue. It's when I then try to send the same request from our file server, that I get the errors. I tried using a preflight request with all of the correct request headings, but received the same 400 Bad Request error.

Does anyone have any suggestions as to what I might be doing wrong?

Upvotes: 0

Views: 147

Answers (2)

danabaillie
danabaillie

Reputation: 75

What fixed it was switching from HTTP1.0 to HTTP1.1, adding the host header and changing the uri.

The logs didn't tell us anything, and the params were ok. The problem was not fully grasping the HTTP header requirements.

Upvotes: 0

EugZol
EugZol

Reputation: 6545

Well, just guessing from what you've said:

request=600&key=&newKey=danasecretkey&

It's likely that you have something like params.require(:key) in your controller. And your request is missing that parameter.

Rails will respond with 400 status in case you missed some require'd params.

Upvotes: 1

Related Questions