How do I repeat the form POST request programmatically - ruby

When I visit the site http://www.jetstar.com/au/en/home
And fill the form then submit.
It will send a POST request then redirect me to new page show the ticket price page(HTML).
I can get the expected result in the second GET response
However, When I try to repeat the POST request with Ruby or Charles
I will get 302 Found error.
I don't get it.
Ruby
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 request params
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
The first time response (SUCCESS) but cat not repeat it programmatically
<!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">
...

This is most probably because of the CSRF verification, Sites users CSRF to validate the request to make sure the form submission came from the same site.
In your case, you try to submit a form from a different source and hence the verification fails.
If you want to do the above, I recon to do a screen scraping by using a library like capybara
read more about CSRF here

Related

Laravel Dompdf taking too long to download pdf

I want to make a pdf invoice from blade template using Dompdf in Laravel 5.5.
The problem is when clicking on the download button the page is loading and after ~3 min i the pdf starts downloading.
Why is it taking so long?
the download link
<i class="fa fa-file-pdf-o"></i> Download Invoice
web route:
Route::get('/order/download-invoice/{OrderID}', 'Admin\AdminOrderController#downloadOrderInvoice')->name('admin.download-invoice');
a simple template (invoice.blade.php)
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other
head content must come *after* these tags -->
<title>Invoice</title>
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}" media="screen">
</head>
<body>
<div>{{ $invoice->InvoiceTitle }} </div>
</body>
</html>
donwload invoice controller function:
use Barryvdh\DomPDF\Facade as PDF;
public function downloadOrderInvoice($OrderID){
$invoice = Invoice::where('OrderID', $OrderID)->first();
$pdf = PDF::loadView('invoice.invoice', compact('invoice'))->setPaper('a4', 'landscape');
return $pdf->download('invoice.pdf');
}
What i did wrong? Did i miss something?
UPDATE
clear the header and using EXTERNAL CDN bootstrap works.
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
Why is not using the local bootstrap using asset???
<link href="{{asset('css/bootstrap.min.css')}}" rel="stylesheet">

Laravel 5.2 sending email as plain text, not html

Recently, I have upgraded my project from Laravel 5.1 to Laravel 5.2 and I am facing a strange issue.
The emails I was sending in HTML format are not getting sent as plain text with html tags inside.
The email body and subject are configurable so I read them from database, replace the variable values and set them as a body and subject.
With Laravel 5.1 there was no issue with it. The code I am using to send email is as below:
Mail::send('layouts.email', $emailData, function($message) use ($emailData, $email_subject){
$message->to($emailData['to'], $emailData['name'])->subject($email_subject);
});
I also have tried,
Mail::send(['html' => 'layouts.email'], $emailData, function($message) use ($emailData, $email_subject){
$message->to($emailData['to'], $emailData['name'])->subject($email_subject);
});
The layout.email.blade.php template is as below:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
{{$message_body}}
</body>
</html>
But the problem is still there. Can anybody guide me please?

Twitter Card Validation

Can anybody see whats wrong with this code, to say why this isnt validating using
https://dev.twitter.com/docs/cards/validation/validator
<meta name="twitter:card" content="product">
<meta name="twitter:site" content="#Agora_snapbacks">
<meta name="twitter:creator" content="#Agora_snapbacks">
<meta name="twitter:title" content="Agora Black Beanie">
<meta name="twitter:description" content="View our varied collection of beanies by Agora">
<meta name="twitter:image:src" content="http://agoraclothing.com/images/detailed/1/LOGOB_BLACK.JPG">
<meta name="twitter:data1" content="29.99">
<meta name="twitter:label1" content="Price">
<meta name="twitter:data2" content="United Kingdom">
<meta name="twitter:label2" content="Locaion">
http://agoraclothing.com/shop/hats/beanies/agora-black-beanie.html
Your issue may be in the price/data1 field. You may have to add the pound symbol before 29.99. I can't be positive but it's worth a try. --David

document type does not allow element "div" here; assuming missing "object" start-tag

Error Line 18, Column 19: document type does not allow element "div" here; assuming missing "object" start-tag
Please see the page source below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta name="keywords" content="Karnataka,Bangalore_Rural,Healthcare,Office_Assistant,Kerala,Ernakulam,IT_Hardware_Networking,Engineer,Sales___Marketing,Executive,Maharashtra,Mumbai_City,Retailing,Manager,Kollam,CRM_CallCentres_BPO_ITES_Med.Trans,Customer_Care,Hotel_Travel_Tourism_Airlines_Hospitality,Front_Office_Staff,Andhra_Pradesh,Hyderabad,IT_Software,Java_Developer,Pathanamthitta,Manufacturing_Industrial,Educational_Training,Teacher,Engineering_Projects"/>
<meta name="description" content="The best job oriented resume sharing system. Create and Publish your online resumes for FREE. Search and apply your dream jobs for FREE. Post your jobs for FREE."/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<div id="fb-root"></div>
I do believe you need to put the < div > inside a < body > section.

Tab in Firefox shows improper charset while loading

While loading the content, Firefox (in Ubuntu, Windows, MacOs) shows for a second improper charset (namely Czech letters). When the content is loaded, it shows a proper charset.
Safari, Explorer, Opera shows tab when loading correctly.
Html head is
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="shortcut icon" href="favicon.ico">
<title><?=$lang_header_dict;?></title>
<meta name="description" content="<?=$lang_head_description?>">
<meta name="keywords" content="<?=$lang_head_content?>">
<meta name="author" content="<?=$lang_head_author?>">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" title="hvalur" href="style.css">
<script type="text/javascript">
function setfocus() {
document.form1.search_string.focus();
}
function popitup(url) {
newwindow=window.open(url,'name','height=400,width=800, scrollbars=yes');
if (window.focus) {newwindow.focus()}
return false;
}
</script>
</head>
Title contains Czech national characaters.
Even with the meta line before the title line, your page's charset may be overridden by Apache's default charset. This is by design.
To solve this issue, add the following to your config file:
AddDefaultCharset Off
See: http://padawan.info/en/2004/07/debugging-chars.html
Placing meta tag
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
before
<title><?=$lang_header_dict;?></title>
shows correct charset and national characters.

Resources