【问题标题】:overriding Content-Type cause Internal Server Error覆盖 Content-Type 导致内部服务器错误
【发布时间】:2014-02-24 09:06:27
【问题描述】:

我正在做一个 iOS 应用程序,我需要自己设置 Content-Type 标头。

每当我覆盖 HTTP 标头时,Web 服务器都会返回 500 - 内部服务器错误。

所以我尝试使用 PHP 代码来检查这是 iOS 还是服务器端错误。

    $target_url = 'http://myserver.com';
    $file_name_with_full_path = realpath('8.jpeg');
    $post = array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$target_url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=--xxx"));
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $result=curl_exec ($ch);
    curl_close ($ch);
    echo $result;

上面的代码响应内部服务器错误。

但是每当我删除波纹管时,它都可以正常工作。

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=--xxx"));

最后我尝试使用 Chrome Postman 插件重新生成问题。我得到了同样的结果。如果我将Content-Type 设置为multipart/form-data,我最终会遇到同样的问题。

apache 或 php 配置是否与接受覆盖标头有关?

感谢任何有关解决此问题的线索。

【问题讨论】:

  • 检查您的服务器错误日志。
  • 我联系了服务器管理员,他说没有记录错误。我真的很困惑。
  • 尝试开启 PHP 错误。在文件顶部添加in_set(display_errors,1);

标签: php ios apache curl http-headers


【解决方案1】:

当您使用参数作为param => @/test/file.txt 时,它默认使用分段文件上传。所以当你改变它时,你会得到错误。

只有去掉文件上传参数才能修改Header(没有任何错误)。

【讨论】:

    猜你喜欢
    • 2014-11-26
    • 1970-01-01
    • 2015-11-23
    • 2013-08-11
    • 2012-03-29
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多