开发者

Manual POST request

Scenario: I have logged into a website, gained cookies etc, got to a particular webpage with a form + hidden fields. I now want to be able to create my own http post with my own hidden fo开发者_运维知识库rm data instead of what is on the webpage and verify the response instead of using the one on the webpage.

Reason: Testing against pre-existing data (I know, I know) which could be different on each environment hence no predictable way to use it. We need a workaround.

Is there any way to do this without manually editing the existing form and submitting that? Feels a little 'hacky'.

Ideally, I would like to say something like:

browser.post 'url', 'field1=test&field2=abc'


I would probably switch to mechanize to muck around at the protocol level. Something like this added to your script

b = WWW::Mechanize.new
 b.get('http://yoursite.com/current_page') do |page|
 # Submit the login form
 my_form = page.form_with(:action => '/post/url') do |f|
   f.form_loginname  = 'tim'
   f.form_pw         = 'password'
 end.click_button
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜