问题描述
我想从使用JSON数据来设置自定义搜索参数的网站检索数据,这似乎是通过AJAX请求的.传输的数据显示在Firebug中的XHR-> Request Payload下:
I want to retrieve data from a website that uses JSON data to set custom search parameters which seem to be requested via AJAX. The data transmitted shows up under XHR->Request Payload in Firebug:
{"filters": [{"action": "post", "filterName": "Hersteller", "ids": [269],
"settingName": "Hersteller", "settingValue": "ValueA"},
{"action": "delete", "filterName": "Modelle",
"settingName": "Modelle", "settingValue": ""}]}
该站点不传输任何POST参数,而仅传输此JSON编码的数据以应用搜索条件.使用Mechanize将此数据作为发布参数传递不起作用.
The site doesn't transmit any POST parameters but only this JSON encoded data to apply search criteria. Passing this data as post parameters with Mechanize doesn't work.
如何在Ruby on Rails中使用Mechanize或Faraday传输这些数据?
How can this data be transmitted using Mechanize or Faraday in Ruby on Rails?
推荐答案
使用Mechanize,您可以做到:
With Mechanize you would do:
agent.post url, data.to_json, {'Content-Type' => 'application/json'}
这篇关于如何在Ruby中使用Mechanize或Faraday发送JSON表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!