5

I am calling some post request using rails activeresource, however all the parameters are sent as query string and the result is that the called url is too long and I get WEBrick::HTTPStatus::RequestURITooLarge exception.

So I need to send the parameters in the request body instead, however I couldn't find how to do this.

Thanks a lot

  • Post request data is sent in the request body already. Are you definitely doing a POST request? see http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request – Max Williams Nov 19 '14 at 14:43

3 Answers3

6

To send a post request in activeresource you should reference the documentation

For example you can do this

#Entity.post(custom_method_name, options = {}, body = '')
Company.post(:add_role, nil, {user_id: 1, role_id: 2}.to_json)

Tell me if you need anything else.

khaled_gomaa
  • 3,382
  • 21
  • 24
0

So, I think you are doing the post request within a link. Anchor by default will create the query parameter. But if you use button and that does send the data by default in post method send as request body like a form of post method. Please try out the following the code snippets:

button_to 'Your post requesting link name', something_path(:your_params => :will be here) 

Let me know if this works!

Thanks.

user229044
  • 232,980
  • 40
  • 330
  • 338
Rubyrider
  • 3,567
  • 1
  • 28
  • 34
-1

Try to install thin server instead of Webrick, read these answer-1, answer-2.

Or, Add webrick.rb file to config\initializers directory, and add the following code:

if defined?(WEBrick::HTTPRequest)
  WEBrick::HTTPRequest.const_set("MAX_URI_LENGTH", 10240)
end

Read also this answer.

Community
  • 1
  • 1
Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45
  • The question is mostly about sending parameters as a request body then query string. Configuring the server to allow or increase the size of the uri shouldn't be the solution in so many cases I guess. – Rubyrider Nov 19 '14 at 14:53