title: How do I pass the form data for POST call using mechanize in ruby
body: <p>I have a post call that requires form data to be sent in place of usual payload data.
  The POST call details are as follows: </p>
  
  <pre><code>.....
  .....
  Request Method:POST
  Status Code:200 OK
  Response Headers
  view source
  Content-Type:text/html;charset=UTF-8
  Date:Mon, 06 Apr 2015 07:46:03 GMT
  Server:Apache-Coyote/1.1
  Transfer-Encoding:chunked
  Request Headers
  view source
  Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding:gzip, deflate
  Accept-Language:en-US,en;q=0.8
  Cache-Control:max-age=0
  Connection:keep-alive
  Content-Length:1777
  Content-Type:application/x-www-form-urlencoded
  Cookie:JSESSIONID=F092185CFE09E4F99C2324A05D56DD14; username=root; doNotShowStartupOnLoad=true
  Host:192.x.x.x.
  Origin:https://192.x.x.x
  Referer:https://192.x.x.x/login.......
  User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36
  Query String Parameters
  view source
  view URL encoded
  dojoIframeSend:true
  request.preventCache:1428306581553
  Form Data
  view source
  view URL encoded
  savedReportsInclude:true
  fromDetailsPage:true
  launchCommand:savedReports
  reportType:detailed_sw_report
  reportDisplayName:Detailed Software
  formSubmitId:0.6209534616209567
  viewType:createCase
  reportCategory:Device
  reportName:detailed_sw_report
  scopeInstance:
  scopeInstanceKey:
  extFilterInstance:
  extFilterInstanceKey:
  apFilterInstance:
  apFilterInstanceKey:
  attrGroupNames:
  savedScopeName:
  command:addAndRunReport
  weekDaysBool:false
  weekDaysBool:false
  weekDaysBool:false
  weekDaysBool:false
  weekDaysBool:false
  weekDaysBool:false
  weekDaysBool:false
  reportFile:nothing
  exportNowMode:0
  selectedColumnList:
  hiddenColumnList:
  fixedColumnList:
  selectedDisplayColumnList:
  hiddenDisplayColumnList:
  fixedDisplayColumnList:
  customizableReportsViewList:
  sortOrderColumnList:
  sortingColumnList:
  emailServerSet:false
  defaultFilterValuesList:
  defaultFilterkeyList:
  filterInternalNames:
  settingsContentDisplay:display
  scheduleContentDisplay:display
  runContentDisplay:display
  savePath:/localdisk/ftp/reports/DetailedSoftware/&lt;ReportTitleName&gt;_&lt;yyyymmdd&gt;_&lt;HHMMSS&gt;
  reportFromContext:false
  reportDescriptorType:2
  doNotIncludeReportsList:
  tempReportTitle:
  maxRowsInSingleGraph:0
  singleGraphOmittedRows:0
  htmlEmailAddr:
  htmlEmailSubject:
  graphicalPageSize:
  includeEmailWithExport:false
  includeReportAsAttachmentWithExport:false
  totalRecordCount:
  totalRecordInfo:
  htmlPageSize:
  virtualDomainChildrenCount:0
  customizedReportSizeList:
  anyDomainChildrenPresent:false
  pagingContextId:
  reportTitle:1213
  reportAggregatorName:detailed_sw_report
  extFilterTF0:
  extFilterTF1:
  extFilterTF2:
  extFilterTF3:
  reportSize:50
  destType:
  emailAddr:
  csrf_token:71d89916ee764fa761554b3018f7790f0dc531db23728809e177b9b51ef976a8
  csrf_token:71d89916ee764fa761554b3018f7790f0dc531db23728809e177b9b51ef976a8
  </code></pre>
  
  <p>I am trying to send this data as:
  FORM_DATA is where data is defined in the form: </p>
  
  <pre><code>FORM_DATA = {
          testcase1: {
              savedReportsInclude:true    ,
              fromDetailsPage:true         ,
              launchCommand:"savedReports"  ,
              reportType:"detailed_sw_report",
              .
              .
              .
   }
  }   
  </code></pre>
  
  <p>This is my code trying to POST the cal and do validation.</p>
  
  <pre><code>TestDataTest::FORM_DATA.each do |k,v|
    puts k, v
    form_data = JSON.parse(v.to_json)
  
  
   url = "...something/reportsAction.do"
    $agent.post url, form_data.to_json,  {'Content-Type' =&gt; 'application/json'}
    response = $agent.page.body
    puts "Response: #{response}"
  
  end
  </code></pre>
  
  <p>The response I get says at the end of the response:
  "Unexpected error: Please refer to the log files for further information."</p>
  
  <p>where as in developer tool , I dont see this message.Please help me how to submi POST call with Form data (I am using mechanize gem and ruby)</p>