title: Download file using wp_remote_post request from API
body: <p>I'm making an API request to an endpoint that based on the given parameters and details, it'll send back a report in a PDF format for me to view with the details I sent over to it. I'm using WordPress using <code>wp_remote_post</code> but having trouble downloading the file to the computer.</p>
  
  <p>This question about <a href="https://stackoverflow.com/questions/25558119/php-rest-download-file">downloading a file in PHP via REST</a> is helpful, but not quite dealing with the same sort of thing/scenario and so I'm stuck on how to get it to work how I need it to.</p>
  
  <p>This is the response I'm getting back using PHP <code>var_dump</code>:</p>
  
  <pre><code>'date' =&gt; string 'Thu, 10 May 2018 11:25:00 GMT' (length=29)
  'server' =&gt; string 'Apache/2.4.7 (Ubuntu)' (length=21)
  'content-disposition' =&gt; string 'attachment; filename="xyz.pdf"' (length=37)
  'cache-control' =&gt; string 'no-cache, private' (length=17)
  'x-ratelimit-limit' =&gt; string '60' (length=2)
  'x-ratelimit-remaining' =&gt; string '58' (length=2)
  'content-type' =&gt; string 'application/pdf' (length=15)
  </code></pre>
  
  <p>In the body part of the response I'm getting this:</p>
  
  <pre><code>  'body' =&gt; string '%PDF-1.4
  1 0 obj
  &lt;&lt;
  /Title ( title )
  /Creator ( creator )
  /Producer ( producer )
  /CreationDate ( creationdate )
  '... (length=22237)
  </code></pre>
  
  <p>I believe from the response that <code>wkhtmltopdf</code> is the library/framework which is creating the PDF that is being sent back. How can I have this file downloaded to the computer as a PDF file to the user that requested it?</p>
  
  <p>I've tried echoing the response and using <code>urldecode</code> but I'm not really sure what kind of response this is and how to deal with it.</p>