检查我的 xml 响应

发布于 2024-09-26 02:37:25 字数 1424 浏览 3 评论 0 原文

有人可以检查 xml 回复字符串吗?用户说它与 XML 不兼容并且标头错误。当我查看源代码时,我看到这个

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response><task_no_added>54</task_no_added><errorMessage></errorMessage></response>

http://itpscan.info/XML/add_item.php

这是在 firebug 中找到的标头信息...

Response Headersview source
Date    Sun, 03 Oct 2010 22:50:03 GMT
Server  Apache mod_fcgid/2.3.5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By    PHP/5.2.13
Keep-Alive  timeout=5, max=100
Connection  Keep-Alive
Transfer-Encoding   chunked
Content-Type    text/html
Request Headersview source
Host    itpscan.info
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://xxxxxx.info/XML/add_item.php

添加: 我尝试添加一个 xml 标头,我们将看看现在是否有效......

header ("Content-Type:text/xml");  
$xml_writer = new XMLWriter();
$xml_writer->openMemory();
$xml_writer->startDocument('1.0', 'UTF-8', 'yes');
$xml_writer->startElement('response');      

Can someone check a xml reply string. User said it is not XML compatible and has bad header. When I do a view source, I see this

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response><task_no_added>54</task_no_added><errorMessage></errorMessage></response>

http://itpscan.info/XML/add_item.php

Here is header info found in firebug...

Response Headersview source
Date    Sun, 03 Oct 2010 22:50:03 GMT
Server  Apache mod_fcgid/2.3.5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By    PHP/5.2.13
Keep-Alive  timeout=5, max=100
Connection  Keep-Alive
Transfer-Encoding   chunked
Content-Type    text/html
Request Headersview source
Host    itpscan.info
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://xxxxxx.info/XML/add_item.php

Addition:
I tried adding a xml header, we will see if that works now...

header ("Content-Type:text/xml");  
$xml_writer = new XMLWriter();
$xml_writer->openMemory();
$xml_writer->startDocument('1.0', 'UTF-8', 'yes');
$xml_writer->startElement('response');      

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饭团 2024-10-03 02:37:25

这是有效的 XML。您可以在此处自行验证

您的用户软件可能会被标头的 standalone 属性所困扰,这种情况并不常见,但是 合法

标记声明可以影响从 XML 处理器传递到应用程序的文档内容;例如属性默认值和实体声明。 独立文档声明可能作为 XML 声明的组成部分出现,表明是否存在此类声明 [...]

您可以将其删除,或者说服序列化程序不要生成它,如果你的用户顽固不化。

编辑:查看 HTTP 标头,我会尝试 Content-Typetext/xml 而不是 text/html< /code> (假设您发布的 XML 就是您在正文中发送的所有内容)。

This is valid XML. You can verify it yourself here.

Your user's software may be tripped up by the header's standalone attribute, which is uncommon, but legal:

Markup declarations can affect the content of the document, as passed from an XML processor to an application; examples are attribute defaults and entity declarations. The standalone document declaration, which may appear as a component of the XML declaration, signals whether or not there are such declarations [...]

You can just remove it, or convince your serializer to not generate it, if your user is implacable.

EDIT: Looking at the HTTP headers, I'd try a Content-Type of text/xml rather than text/html (assuming that the XML you posted is all you're sending in the body).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文