首页 > 解决方案 > 服务器返回内容类型 application/x-httpd-php5 而不是 application/json

问题描述

我的 PHP 代码返回一个 JSON 字符串并设置为响应标头Content-Type: application/json

在 localhost 上它工作正常,它只返回我传递的 JSON 字符串。但是,在我的浏览器网络/标头上向远程服务器请求,内容类型是application/x-httpd-php5. std-output而内容,在 json 字符串之前,它会打印和该标题字符串中的文本:

X-Powered-By: PHP/7.2.8

Cache-Control: private, must-revalidate

Date: Wed, 08 Aug 2018 02:49:36 GMT

Content-Type: application/json

pragma: no-cache

expires: -1

X-Debug-Token: 187f4e

之后我得到了我发送的 json 字符串。

我的 PC 和主机的 PHP 版本是 PHP 7.2。我使用阿帕奇。托管也应该。但是,从浏览器响应标头中,我看到Server: nginx.

从服务器到 Mime 类型,我得到了 application/json -> json。我上传了一个 .json 文件,我得到了Content-Type: application/json. 我设置为我的 .htaccess 文件

AddDefaultCharset utf-8
AddType 'application/json; charset=UTF-8' .json

但仍然没有任何变化。

我不知道为什么在我的本地主机上我得到了Content-Type: application/json,但在我得到的主机上application/x-httpd-php5

这是原始响应:

HTTP/2.0 200 OK
server: nginx
date: Wed, 08 Aug 2018 03:31:45 GMT
content-type: application/x-httpd-php5
cache-control: max-age=0
expires: Wed, 08 Aug 2018 03:31:44 GMT
X-Firefox-Spdy: h2

标签: phpjsonapachemime-typescontent-type

解决方案


推荐阅读