简体   繁体   中英

Get content of a request with 'content-disposition: attachment' header in Php

I need to read some JSON from a third-party service (namely Zoho) over which I don't have any sort of control; the service uses a content-disposition: attachment header that prevents me from getting the actual request content. Opening the URL in a browser works correctly, so does the curl {url} bash command, but no matter how I try to get the content using Php, I get a different content from what I get using the browser method. I tried using wp_remote_get() in a WordPress plugin, cURL library in a simple Php script, executing curl using exec() , but none of it worked.

Is there any way to get the actual body of request with a content-disposition: attachment header with Php like the curl bash command does?

If the server response header contains content-disposition: attachment it should mean it tries to send a file (acting like download server), but the same you should receive when you open it on browser.

Another thing to pay attention is, probably it changes the location (does redirect), so the browser can normally follow to new location, while in your curl script if you don't have that option set (CURLOPT_FOLLOWLOCATION) to true, then it will not follow to new location.

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