简体   繁体   English

使用 PHP 中的“content-disposition:attachment”标头获取请求的内容

[英]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;我需要从我无法控制的第三方服务(即 Zoho)读取一些 JSON; the service uses a content-disposition: attachment header that prevents me from getting the actual request content.该服务使用content-disposition: attachment标头,阻止我获取实际的请求内容。 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.在浏览器中打开 URL 可以正常工作, curl {url} bash 命令也是如此,但是无论我如何尝试使用 Php 获取内容,我都会获得与使用浏览器方法获得的内容不同的内容。 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.我尝试在 WordPress 插件中使用wp_remote_get() ,在简单的 PHP 脚本中使用 cURL 库,使用exec()执行 curl ,但都没有奏效。

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?有什么方法可以像 curl bash 命令那样使用content-disposition: attachment header with Php 获取请求的实际主体吗?

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.如果服务器响应标头包含content-disposition: attachment它应该意味着它尝试发送一个文件(就像下载服务器一样),但是当你在浏览器上打开它时你应该收到同样的信息。

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.另一件要注意的事情是,它可能会更改位置(确实重定向),因此浏览器通常可以跟随到新位置,而在您的 curl 脚本中,如果您没有将该选项设置 (CURLOPT_FOLLOWLOCATION) 为 true,那么它将不跟随到新位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM