Search code examples
phpxmlhttp-headersmime-typesatom-feed

PHP header issue


I have set HTTP header in PHP as:

header("Content-Type: application/xml"); 

And I got following response:

<?xml version="1.0" encoding="utf-8"?>
<feedback>
    <result>False</result>
</feedback>

But when I check headers, it says the response type is application/atom+xml . I need this in application/xml format. What could be the reason for this issue?


Solution

  • There's no reason why that shouldn't work. I've just tried a simple test case with that xml and it certainly works for me.

    <?php
    header("Content-Type: application/xml");
    ?><?xml version="1.0" encoding="utf-8"?>
    <feedback>
        <result>False</result>
    </feedback>
    

    Either there is more to your php that you're not showing us, or possibly there is something misconfigured in your server software.

    Update

    Based on the information you provided in your answer, I'd say you could fix this by changing your root element to anything that doesn't start with <feed. As I said in my comment, something is incorrectly interpreting this as being an Atom feed and rewriting the content-type.

    That said, there are assumedly other strings (e.g. <rss) that might trigger other rewrites of the content-type, so it would be preferable if you could track down whatever system was responsible for the error and get rid of it.