简体   繁体   English

标头中的“ Content-Type”未更改

[英]“Content-Type” in header is not changing

I'm trying to call Rest web service with cURL that does next: 我正在尝试使用下一步执行的cURL调用Rest Web服务:

  1. generate certificate 生成证书
  2. download this certificate 下载此证书

Every one of those functions is working alone, but when gathering them in one service the download dialog is not opening, and I'm always getting text/html as Content type, I saw it via Firebug. 这些功能中的每个功能都可以单独使用,但是当将它们收集到一项服务中时,下载对话框不会打开,并且我始终以text / html作为Content类型,这是通过Firebug看到的。

This is the code of the downloading (from php.ent): 这是下载代码(从php.ent):

 if (file_exists($filename)) {
            header("Content-Length: " . filesize($filename));
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=' . $certName);

            readfile($filename, false);
            exit();
        }

and here's how I'm calling my service: 这是我给我的服务打电话的方式:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
$dat=array( 
 // many args
            );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dat);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
    if ($curl_errno > 0) {
       echo "cURL Error ($curl_errno): $curl_error\n";
    } else {
       echo "Data received: $data\n";
   }
    curl_close($ch);

What's wrong guys? 你们怎么了?

  1. Your browser makes an HTTP request 您的浏览器发出HTTP请求
  2. Your server runs a PHP script that runs cURL 您的服务器运行一个运行cURL的PHP​​脚本
  3. cURL gets data from another server and ignores the Content-Disposition header because it is cURL and not a browser cURL从另一台服务器获取数据,并忽略Content-Disposition标头,因为它是cURL而不是浏览器
  4. The PHP script running cURL outputs Data received: $data as the body of an HTML document 运行cURL的PHP​​脚本输出输出Data received: $data作为HTML文档的正文
  5. The browser receives that HTTP document 浏览器收到该HTTP文档

If you want the cURL using program to act as a proxy, then you need to proxy the HTTP headers and not add extra data to the output. 如果您希望使用程序的cURL充当代理,则需要代理HTTP标头,而不要在输出中添加额外的数据。

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

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