Send pdf from wp_remote_get to browser
-
I’m integrating a wordpress site with an external API. I have a form that posts to my server and I call a function on my server that makes a wp_remote_get call to the external API.
The external API returns a PDF, with headers like:
[date] => Fri, 18 Aug 2017 15:59:19 GMT
[x-powered-by] => Servlet/3.0
[cache-control] => no-cache
[content-type] => application/pdf;charset=utf-8
[content-language] => en-USAnd the response body is the PDF in nasty string format, which seems like a good start.
How do I pass this PDF to the user’s browser? ie,
$response = wp_remote_get( $url, array ( //stuff the request needs));
if (is_wp_error ($response)) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
//What here?
}I have to hit my server first, cannot post the form directly to the external API.
- The topic ‘Send pdf from wp_remote_get to browser’ is closed to new replies.