douzhuan4406 2017-03-15 07:19
浏览 75
已采纳

为什么PHP header()不起作用?

<?php
    header('Content-type: application/xml');
    echo "test";
?>

I use this code and its not working in MAMP and the response headers are:

Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Wed, 15 Mar 2017 15:12:45 GMT
Server:nginx/1.11.4
Transfer-Encoding:chunked
X-Powered-By:PHP/7.1.1
  • 写回答

1条回答 默认 最新

  • dongqiao1888 2017-03-15 08:58
    关注

    Try this instead:

    <?php
        header('Content-type: application/xml');
        echo "<example>hello, world!</example>";
    

    Gives you:

    Connection:Keep-Alive
    Content-Type:application/xml
    Date:Wed, 15 Mar 2017 15:12:45 GMT
    Server:nginx/1.11.4
    Transfer-Encoding:chunked
    X-Powered-By:PHP/7.1.1
    

    Links:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部