RSS 中的 URL 编码链接会破坏链接

发布于 2024-11-02 06:10:13 字数 543 浏览 3 评论 0原文

为了获得有效的 XML RSS 提要,我需要对包含“&”的链接进行 url 编码在查询字符串中。但是,当用户在浏览器中查看 RSS 源时,链接不会被解码,因此当他们单击链接时,结果页面会被破坏,因为查询字符串参数没有被正确读取。

例如

http://www.mysite.com?foo1=bar1&foo2=bar2,在浏览器中查看时为 http://www.mysite.com?foo1=bar1%26foo2=bar2,参数 foo1 被视为 bar1%26foo2=bar2,而不是将水果和饮料分成两个单独的参数。

将我的链接包装在标签中而不对其进行编码是可行的,但是在我的 MRSS 提要中,我有一些字段,例如包含标签会破坏 XML。

我怎样才能正确编码我的链接以便一切正常?

In order to have a valid XML RSS feed, I need to url encode my links which contain '&' in the query string. However, when a person views the RSS feed in a browser, the links are not decoded, so when they click on the link the resulting page is broken because the query string parameters are not being read correctly.

E.g.

http://www.mysite.com?foo1=bar1&foo2=bar2, when viewed in the browser as http://www.mysite.com?foo1=bar1%26foo2=bar2, the parameter foo1 is being taken as bar1%26foo2=bar2 instead of splitting fruit and drink into two separate parameters.

Wrapping my links in tags and not encoding them work, but then in my MRSS feed I have fields such as where including a tag breaks the XML.

How can I go about correctly encoding my links so that everything works?

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

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

发布评论

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

评论(1

呆橘 2024-11-09 06:10:13

简短答案

使用&amp

长答案

如果您查看https://stackoverflow.com/feeds/tag/xml,这个问题的条目看起来像这样,并且您的示例链接在 IE 中查看时工作正常

您的示例链接

http://www.mysite.com?foo1=bar1&foo2=bar2

您的条目

<entry>
        <id>https://stackoverflow.com/questions/5705246/url-encoded-links-in-rss-breaks-links</id>
        <re:rank scheme="http://stackoverflow.com">0</re:rank>
        <title type="text">URL encoded links in RSS breaks links</title>
        <category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="xml"/><category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="rss"/><category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="urlencode"/>
        <author>
            <name>Choy</name>
            <uri>https://stackoverflow.com/users/252529</uri>
        </author>
        <link rel="alternate" href="https://stackoverflow.com/questions/5705246/url-encoded-links-in-rss-breaks-links" />
        <published>2011-04-18T15:30:11Z</published>
        <updated>2011-04-18T15:35:43Z</updated>
        <summary type="html">
            <p>In order to have a valid XML RSS feed, I need to url encode my links which contain '&amp;' in the query string.  However, when a person views the RSS feed in a browser, the links are not decoded, so when they click on the link the resulting page is broken because the query string parameters are not being read correctly.</p>

<p>E.g.</p>

<p><a href="http://www.mysite.com?foo1=bar1&amp;foo2=bar2" rel="nofollow">http://www.mysite.com?foo1=bar1&amp;foo2=bar2</a>, when viewed in the browser as <a href="http://www.mysite.com?foo1=bar1%26foo2=bar2" rel="nofollow">http://www.mysite.com?foo1=bar1%26foo2=bar2</a>, the parameter foo1 is being taken as bar1%26foo2=bar2 instead of splitting fruit and drink into two separate parameters.</p>

<p>Wrapping my links in  tags and not encoding them work, but then in my MRSS feed I have fields such as  where including a  tag breaks the XML.</p>

<p>How can I go about correctly encoding my links so that everything works?</p>

        </summary>
    </entry>

Short answer

use &amp

Long answer

If you look at https://stackoverflow.com/feeds/tag/xml, the entry for this question looks like so and your sample link works fine when viewed in I.E.

Your sample link

http://www.mysite.com?foo1=bar1&amp;foo2=bar2

Your entry

<entry>
        <id>https://stackoverflow.com/questions/5705246/url-encoded-links-in-rss-breaks-links</id>
        <re:rank scheme="http://stackoverflow.com">0</re:rank>
        <title type="text">URL encoded links in RSS breaks links</title>
        <category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="xml"/><category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="rss"/><category scheme="https://stackoverflow.com/feeds/tag/xml/tags" term="urlencode"/>
        <author>
            <name>Choy</name>
            <uri>https://stackoverflow.com/users/252529</uri>
        </author>
        <link rel="alternate" href="https://stackoverflow.com/questions/5705246/url-encoded-links-in-rss-breaks-links" />
        <published>2011-04-18T15:30:11Z</published>
        <updated>2011-04-18T15:35:43Z</updated>
        <summary type="html">
            <p>In order to have a valid XML RSS feed, I need to url encode my links which contain '&amp;' in the query string.  However, when a person views the RSS feed in a browser, the links are not decoded, so when they click on the link the resulting page is broken because the query string parameters are not being read correctly.</p>

<p>E.g.</p>

<p><a href="http://www.mysite.com?foo1=bar1&amp;foo2=bar2" rel="nofollow">http://www.mysite.com?foo1=bar1&amp;foo2=bar2</a>, when viewed in the browser as <a href="http://www.mysite.com?foo1=bar1%26foo2=bar2" rel="nofollow">http://www.mysite.com?foo1=bar1%26foo2=bar2</a>, the parameter foo1 is being taken as bar1%26foo2=bar2 instead of splitting fruit and drink into two separate parameters.</p>

<p>Wrapping my links in  tags and not encoding them work, but then in my MRSS feed I have fields such as  where including a  tag breaks the XML.</p>

<p>How can I go about correctly encoding my links so that everything works?</p>

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