简体   繁体   English

覆盖内容类型导致内部服务器错误

[英]overriding Content-Type cause Internal Server Error

I am doing an iOS app and I require to set Content-Type headers by my own. 我正在做一个iOS应用,我需要自己设置Content-Type标头。

Whenever I override the HTTP header the web server returns 500 - Internal server error. 每当我覆盖HTTP标头时,Web服务器都会返回500-内部服务器错误。

So I tried with a PHP code to check whether this is iOS or server side error. 因此,我尝试使用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;

The above code response with Internal Server Error. 上面的代码响应为Internal Server Error。

but whenever I remove bellow line, it works fine. 但是只要我删除波纹管,它就可以正常工作。

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

At last I tried to re-generate the issue with Chrome Postman plugin. 最后,我尝试使用Chrome Postman插件重新生成该问题。 I got the same result. 我得到了相同的结果。 If I set Content-Type as multipart/form-data I ended up having the same issue. 如果将Content-Type设置为multipart/form-data我最终会遇到同样的问题。

Is there anything to do with apache or php configurations to accept overriding headers? 与apache或php配置有什么关系,以接受覆盖的标头?

Appreciate any clue on fixing this issue. 感谢有关解决此问题的任何线索。

Whenever you use a parameter as param => @/test/file.txt it uses the multipart file upload by default. 每当您将参数用作param => @/test/file.txt时,默认情况下都会使用分段文件上传。 So when you alter this, you get error. 因此,当您更改此设置时,会出现错误。

You can only alter the Header(without any error) only if you remove the file uploading parameter. 仅当删除文件上传参数后,才能更改页眉(没有任何错误)。

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

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