如何以编程方式重复表单POST请求

时间:2015-05-30 11:51:17

标签: ruby network-programming http-post charles-proxy

当我访问网站http://www.jetstar.com/au/en/home

填写表格然后提交。

它会发送 POST请求,然后将我重定向到新页面显示票价页面(HTML)。

我可以在第二个 GET 响应中获得预期结果

但是,当我尝试使用 Ruby Charles

重复POST请求时

我会收到 302 Found 错误。

我不明白。

红宝石

q_prams = {  
   "ControlGroupSearchView$AvailabilitySearchInputSearchView$DropDownListFareTypes"   =>"I",
   "ControlGroupSearchView$AvailabilitySearchInputSearchView$DropDownListMarketDay1"   =>"9",
   ~~~
   "pageToken"   =>"sLkmnwXwAsY=",
   "ControlGroupSearchView$AvailabilitySearchInputSearchView$fromCS"   =>"yes"
}

res = RestClient.post 'https://booknow.jetstar.com/Search.aspx', q_prams

POST请求参数

ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListCurrency=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListFareTypes=I&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay1=18&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay2=1&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay3=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth1=2015-6&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth2=1968-1&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth3=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_ADT=1&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_CHD=0&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_INFANT=0&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24RadioButtonMarketStructure=OneWay&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination1=MEL&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination2=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination3=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin1=NAN&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin2=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin3=&ControlGroupSearchView%24ButtonSubmit=&__VIEWSTATE=&culture=en-AU&date_picker=&go-booking=&pageToken=sLkmnwXwAsY%3D&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24fromCS=yes&_pe_39b5379c652b_9df496572198=null&locale=en-AU

第一次响应(SUCCESS)但cat不以编程方式重复

<!doctype html><!--paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/--><!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--><!--[if IE 7 ]>    <html lang="en" class="no-js ie7"> <![endif]--><!--[if IE 8 ]>    <html lang="en" class="no-js ie8"> <![endif]--><!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--><html lang="en" class="no-js"><!--<![endif]--><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head class="SB">
  <META http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Jetstar Airways Cheap Flights, Low Fares all day everyday from the world's best Cheap Fare airline</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
  <link rel="icon" href="favicon.ico" type="image/ico">
  <link rel="SHORTCUT ICON" href="favicon.ico">
...

1 个答案:

答案 0 :(得分:1)

这很可能是因为CSRF verification,网站用户CSRF验证请求以确保表单提交来自同一网站。

在您的情况下,您尝试从其他来源提交表单,因此验证失败。

如果您想要执行上述操作,我会使用capybara

等库来重新进行屏幕抓取

详细了解CSRF here