0

I am sending a post request from a Rails app, to an ExpressJS app. In postman it works, however when i send the post request from the Rails app, the params look fine on the rails end but then when the ExpressJS app receives them, they're different?? Specifically in the nested hashes(forms_list). Help. Here is the data:

These are the rails params:

{:respond_url=>"http://localhost:3000/api/v1/crawls/rover_page", :error_url=>"http://localhost:3000/api/v1/crawls/rover_error", :crawl_id=>"5bbf971e0928538630743eb8", :dimension_id=>"eda510527346f84479a6", :next_page=>"", :back_button=>"", :start_url=>"https://hrlb.oregon.gov/bspa/licenseelookup/", :forms_list=>[{"select"=>{"//td[select]/select"=>"lastname"}, "text_field"=>{"//td[2]/input[1]"=>"bac"}}], :clicks_list=>["//input[@type='submit']"], :links_selector=>"//table[2]//tr[td[a]]//td[1]/a", :command_list=>["start_url", "form", "click", "record_links"]}

They are sent with RestClient like so:

new_crawl = RestClient.post("#{ENV['ROVER_URL']}/crawl/new_crawl", params)

These are the params sent in postman that work:

{"respond_url": "http://localhost:3003/api/v1/crawls/rover_page",
"error_url": "http://localhost:3003/api/v1/crawls/rover_error",
"crawl_id": "5bbcfd36092853736bc872d7",
"dimension_id": "123",
"next_page": "",
"back_button": "",
"start_url":"https://hrlb.oregon.gov/bspa/licenseelookup/",
"forms_list":[{"text_field":{"//td[2]/input[1]": "bac"}, "select": {"//td[select]/select": "lastname"}}],
"clicks_list": ["//input[@type='submit']"],
"links_selector": "//table[2]//tr[td[a]]//td[1]/a",
"command_list": ["start_url", "form", "click", "record_links"]
}

And here is the screenshot of how it is interpreted on the ExpressJS side:

ExpressJS data interpreted - WRONG

And THIS is how the data should look (this was sent with the postman data):

ExpressJS data interpreted - Correctly

Cannon Collins
  • 157
  • 1
  • 2
  • 11

1 Answers1

1

I'd point my attention at having valid JSON field names. The slashes and brackets, in particular, are going to have chances to throw a wrench in the spokes somewhere along the way.

While the JSON is valid (somehow), I believe that //td[2]/input[1] is not the greatest fieldname ever contrived and it may not play nice with all the libraries with a stake in your outcome!

Here's a brief discussion on valid/invalid characters in JSON

If you are in control of the structure of the JSON, perhaps it would be better to make bac and lastname the fieldnames and have the selector be the value.

Darren Hicks
  • 4,946
  • 1
  • 32
  • 35