Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • skycro 23 posts 22 karma points
    Apr 07, 2010 @ 20:32
    skycro
    0

    Consuming and RSS Feed and the 500 Error

    I am trying to consume the following rss feed:

    http://www.youversion.com/reading-plans/life-journal-reading-plan/rss

    But I receive the following error:

    System.Net.WebException: The remote server returned an error: (500) Internal Server Error. at System.Net.HttpWebRequest.GetResponse() at umbraco.library.GetXmlDocumentByUrl(String Url)

    Things I have tried:

    • I have ran several rss feeds through the xslt, without any problems. They read and are rendered correctly.
    • I can view the feed in several rss readers. 
    • I have saved the feed as an xml document and can read that document through this xslt as a local document.

    xslt:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <!--<xsl:variable name="url" select="/macro/url" />-->
    <xsl:variable name="url">http://www.youversion.com/reading-plans/life-journal-reading-plan/rss</xsl:variable>;

    <xsl:template match="/">   
    <xsl:if test="$url != ''">
       
        <xsl:variable name="xmlFeed" select="umbraco.library:GetXmlDocumentByUrl($url)" />
        <xsl:value-of select="$xmlFeed" />   
        <xsl:apply-templates select="$xmlFeed//item"  />

    </xsl:if>
    </xsl:template>


    <xsl:template match="item" >
        <div>
            <xsl:value-of select="description" disable-output-escaping="yes" />
           
        </div>
    </xsl:template>
    </xsl:stylesheet>

     

    xml:

    <?xml version="1.0" encoding="utf-8"?><rss version="2.0">
    <channel>
    <description>Prof. Horner's Bible Reading System - YouVersion.com</description>
    <title>Prof. Horner's Bible Reading System - YouVersion.com</title>
    <generator>YouVersion.com</generator>
    <link>http://www.youversion.com/reading-plans/professor-horners-bible-reading-system</link>
    <item>
    <description><![CDATA[<ul><li><a href="http://www.youversion.com/bible/matt/8">Matthew 8</a></li><li><a href="http://www.youversion.com/bible/lev/7">Leviticus 7</a></li><li><a href="http://www.youversion.com/bible/1cor/3">1 Corinthians 3</a></li><li><a href="http://www.youversion.com/bible/1pet/5">1 Peter 5</a></li><li><a href="http://www.youversion.com/bible/job/35">Job 35</a></li><li><a href="http://www.youversion.com/bible/ps/97">Psalm 97</a></li><li><a href="http://www.youversion.com/bible/prov/4">Proverbs 4</a></li><li><a href="http://www.youversion.com/bible/2sam/17">2 Samuel 17</a></li><li><a href="http://www.youversion.com/bible/jer/31">Jeremiah 31</a></li><li><a href="http://www.youversion.com/bible/acts/13">Acts 13</a></li></ul>]]></description>
    <title>Day 97 - Prof. Horner's Bible Reading System - YouVersion.com</title>
    <guid>http://read.ly/r/J.1Z</guid>
    <link>http://read.ly/r/J.1Z</link>
    <pubDate>Wed, 07 Apr 2010 16:57:48 +0000</pubDate>
    </item>
    </channel>
    </rss>

     

    Assuming that I am doing things correctly, I think "YouVersion" is blocking requests that do not come from a browser.

    I really hope that I am not doing things correctly.

    What do you think?

  • mike_h 25 posts 49 karma points
    Apr 07, 2010 @ 20:55
    mike_h
    1

     

    See if this helps:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxml="urn:schemas-microsoft-com:xslt"
            xmlns:msxsl="urn:schemas-microsoft-com:xslt"
            xmlns:wm="urn:writemedia-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    
    
      <xsl:output method="xml" omit-xml-declaration="yes"/>
    
      <xsl:param name="currentPage"/>
      <xsl:variable name="max">
        <xsl:choose>
          <xsl:when test="/macro/max != ''">
            <xsl:value-of select="/macro/max" />
          </xsl:when>
          <xsl:otherwise>5</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
    
      <!-- start writing XSLT -->
      <xsl:template match="/">
        <xsl:variable name="xmlcontent" select="wm:getRSS()" />
        <ul style="list-style:none;">
          <xsl:apply-templates select="$xmlcontent/rss/channel/item" />
        </ul>
      </xsl:template>
    
      <xsl:template match="item">
        <xsl:if test="position() &lt; number($max)">
          <li>
            <h3>
              <a href="{link}" target="_blank">
                <xsl:value-of select="substring(pubDate,1,16)"/> - <xsl:value-of select="title"/>
              </a>
            </h3>
          </li>
        </xsl:if>
      </xsl:template>
    
      <msxsl:script language="C#" implements-prefix="wm">
        <![CDATA[
    
            public System.Xml.XmlDocument getRSS()
            {
                try
                {
                    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.localendar.com/public/cardiffbrass?style=D4");
                    request.Headers["Accept-Encoding"] = "gzip";
                    request.Headers["Accept-Language"] = "en-us";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.UserAgent = "Mozilla/4.0+";
                    request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    request.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
    
                    using (System.Net.WebResponse response = request.GetResponse())
                    {
                        using (System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()))
                        {
                            System.Xml.XmlDocument MyRssDocument = new System.Xml.XmlDocument();
                            MyRssDocument.LoadXml(reader.ReadToEnd());
                return MyRssDocument;
                        }
                    }
    
                }
                catch (System.Net.WebException ex)
                {
                    throw new Exception(ex.Message);
                }
    
            }
    
            ]]>
      </msxsl:script>
    </xsl:stylesheet>
  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Apr 07, 2010 @ 20:56
    Jan Skovgaard
    1

    Hi Skycro

    I think you should use the XSLT extension from the umbraco library called "GetXmlDocumentByUrl" so your variable will look like this:

    <xsl:variable name="url" select="umbraco.library:GetXmlDocumentByUrl('http://www.youversion.com/reading-plans/life-journal-reading-plan/rss')" />

    /Jan

  • skycro 23 posts 22 karma points
    Apr 07, 2010 @ 21:57
    skycro
    0

    mike_h,

    thanks, this is my first post on the new forum.  I will take some time to figure out the karma thing.  So I am happy that I guessed right about the header information, but I am even happier that you knew how to do it.

    skycro

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies