简体   繁体   中英

Submit a form on remote site via cURL and PHP, and download the file in response, remote page is html and https

What I am trying is submit a form on remote site, the output of that form is a pdf file which I want to store to my site locally. I want to automate this via cron job, using PHP and cURL.

在此处输入图像描述

Problems:

  1. Remote site is https (even worse it is not properly setup)
  2. The site is html and not PHP but it gives result as if PHP

What I have tried so far

  1. I used cURL in PHP but did not quite work. It simply submits a response which does not include the response from the form submission.

  2. I tried to create remote form on my local host and when I submit form, it does return pdf file but this solution does not uses Curl and hence I cannot automate it.

Code that I have tried so far

<?php 

// set post fields
$post = [
    'bench_sno' => '1',
    'causelist_date' => '2010-10-1',
    'btnSearch'   => 'Search Causelist',
];

$ch = curl_init('http://peshawarhighcourt.gov.pk/app/site/4/p/Causelists_List.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
//var_dump($response);
echo $response;

?>

When I just copy the remote form to my site and submit the form, it does work fine Working Example but the problem is it does not work with cURL. I need to automate this task via cron job, any other solution if available, I can consider.

As came under discussion in the question itself, and pointed out by @vivek_23 to include it in the fields, the form now works

<input type="hidden" name="url" value="http://peshawarhighcourt.gov.pk:443/app/site/4/p/Causelists_List.html">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM