문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

I can't say what the technical explanation. But changing the XML content fixed my issue. It was a slight change. I just added a top level branch element,

<?xml version="1.0" encoding="utf-8"?>
<data>
<feedback>
    <result>True</result>
</feedback>
</data>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top