-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest4-post.php
39 lines (29 loc) · 1018 Bytes
/
test4-post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// How to convert an HTML string to a PDF with a POST request and stream it to the user in the browser
$api_endpoint = "http://selectpdf.com/api2/convert/";
$key = 'your license key here';
$raw_html = "Test HTML string";
$parameters = array ('key' => $key, 'html' => $raw_html);
// Sample POST
// for options use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($parameters),
),
);
$context = stream_context_create($options);
$result = @file_get_contents($api_endpoint, false, $context);
if (!$result) {
echo "HTTP Response: " . $http_response_header[0] . "<br/>";
$error = error_get_last();
echo "Error Message: " . $error['message'];
}
else {
// set HTTP response headers
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"test.pdf\"");
echo ($result);
}
?>