0

I am trying to send these parameters as string

abc = authenticity_token=lXewdcVQRHZb+O9gVZ+E0xG9Mtg2rnTznkEN/wVk2a4=&design[design_code]=xyz&&design[price]=600&design[discount_percent]=10&design[category_ids]=148&design[property_value_ids]=250&design[property_value_ids]=285&design[property_value_ids]=499&design[image_ids]=208133&

post_design_url = 'some url'

agent = Mechanize.new

agent.user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; ru-ru) AppleWebKit/533.2+ (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10"

agent.post(post_design_url, abc)

When i checking out request at my rails server i am getting

Parameters: {}

I am trying to send arrays in this post request. category_ids and property_value_ids

chirag7jain
  • 1,485
  • 3
  • 26
  • 43

3 Answers3

1

I don't use Mechanize, but I think you should add your parameters like this:

agent.post(post_design_url, {
    "authenticity_token" => "lXewdcVQRHZb+O9gVZ+E0xG9Mtg2rnTznkEN/wVk2a4=",
    "design[design_code]" => "xyz",
    "design[price]" => "600"
})
Sir l33tname
  • 4,026
  • 6
  • 38
  • 49
0

I addition to @Sir l33tname answer you can use following format

agent.post(post_design_url, {
  :param1 => 'one', 
  :nested => {:param2 => 'two'},
})
user2622247
  • 1,059
  • 2
  • 15
  • 26
0

I believe the issue you are having is right at the beginning of your query parameters.

I believe you should add quotes around the string, and escape your auth token:

require 'cgi'

abc = "authenticity_token=#{CGI::escape('lXewdcVQRHZb+O9gVZ+E0xG9Mtg2rnTznkEN/wVk2a4=')}&design[design_code]=xyz&&design[price]=600&design[discount_percent]=10&design[category_ids]=148&design[property_value_ids]=250&design[property_value_ids]=285&design[property_value_ids]=499&design[image_ids]=208133&"

I'm pretty sure before, if the quotes around your full string weren't getting you, the = at the end of your authenticity_token probably was.

Phil
  • 271
  • 4
  • 13