0

I have a simple script that curls into a site to get flight information. The site has input for departure city, arrival city, and date. The date field on the actual site uses datepicker with a placeholder format as mm/dd/yyyy, and when a date is selected with date picker the date input field populates with something like 04/14/2019.

My script includes:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.somesite.com");

$curl_data = "dep=YYY&arr=ZZZ&date=04/14/2019";

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);
curl_close($ch);

When I echo the output, it always tell me that I submitted an invalid date. I've tried multiple formats. Any ideas on how to determine the proper date format or what else I might need to do?

Thanks.

  • Submit the form in your browser and see what format the browser sends the data in. Also a lot of datepickers actually have two inputs boxes overlapping to achieve the datepicker functionality. Check the DOM to make sure you don't have a hidden input named `date1` or something similar. – bassxzero Feb 19 '19 at 21:10

1 Answers1

0

When you submit the form on the real site you can check the POST data with the web developers console: How can I debug a HTTP POST in Chrome?

Thomas Leu
  • 826
  • 4
  • 13
  • Did what your link suggested and I got the following for the date: 02/21/2019. When viewing source or url encoded it had 02%2F21%2F2019. I tried that but still not working. – alanpollenz Feb 19 '19 at 21:45
  • `%2F` is a `/` character - see [here](https://www.w3schools.com/tags/ref_urlencode.asp). Try it with the `/` character. – cssyphus Feb 19 '19 at 22:11
  • I’ve tried that as well. I think the page I’m submitting actually redirects to a second page so I’ll take the output from page 1 and try to curl into page 2 tomorrow. Thanks – alanpollenz Feb 20 '19 at 01:16
  • You can enable [autoredirect](https://evertpot.com/curl-redirect-requestbody/) in curl. – Thomas Leu Feb 20 '19 at 06:17
  • Thomas... I enabled redirect this morning and that did the trick. Thanks. – alanpollenz Feb 20 '19 at 13:23