2017-03-15 83 views
0
<?php 
    header('Content-type: application/xml'); 
    echo "test"; 
?> 

我使用此代碼,它不是爲毫安工作和響應標題是:爲什麼PHP header()不起作用?

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 
+0

你嘗試將一些有效的XML? – Scriptman

+3

我不明白。 A的ma不代表Apache嗎?爲什麼這個標記的nginx? – apokryfos

+0

如果您將返回有效的XML,那麼它就可以工作,現在它正在考慮一個空文檔。 –

回答

0

試試這個:

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

爲您提供:

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 

鏈接:

+0

不能正常工作.... – Misaka

+0

有效100%。請參閱工作示例和源代碼鏈接。你做錯了什麼。 –