我解决了这个问题。我分两步做了。首先,我使用ajax将基本url和url参数发送到本地服务器上的php脚本。使用jQuery很容易完成:
jQuery.ajax({
type : "POST",
url : './includes/php/userdata.php',
data: { method: 'get_print_version',
url: base_url,
parameter: query_parameter,
num: num_parameter },
error: function(error) {
console.log("Print version failed");
},
success: function(reault) {
console.log("What is the result?");
}
});
服务器脚本使用cURL将数据发送到最终服务器。因此,基URL和参数不会发布为一个url,而是通过使用CURLOPT_POST和CURLOPT_POSTFIELDS分开。可以使用file_put_contents将服务器响应(pdf)写入文件。如果PDF变大,您将在此处获得内存限制错误。将cURL的答案直接写入pdf文件最好。
if ($_method == 'get_print_version')
{
$url = $_REQUEST['url'];
$parameter = $_REQUEST['parameter'];
$num = $_REQUEST['num'];
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, $num);
curl_setopt($post, CURLOPT_POSTFIELDS, $parameter);
/* write calendar directly to file */
$pdf = fopen('./Calendar.pdf', 'w');
curl_setopt($post, CURLOPT_FILE, $pdf);
curl_exec($post);
curl_close($post);
echo $result;
}