Reputation: 63
I've got an intermittent issue with a sub that goes off to read a twitter rss feed.
95% of the time, it behaves fine and without problems. The remaining 5% it gives me a 400 Bad Request error (even though the rss feed on Twitter is just fine, which suggests that the problem is at my end, not Twitter.)
Code:
Sub RetrieveStories()
'Create a new xmldocument and load the xml into it
Dim rssDoc As New XmlDocument
rssDoc.Load("http://twitter.com/statuses/user_timeline/athersgeo.rss")
'Select each item and put it into our array
Dim nodes As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")
Dim i as integer = 1
divMRSS.InnerHtml = ""
Dim TweetText as string
Dim TweetURL as string
Dim UNameLen as integer = 15
For Each node As XmlNode In nodes
'Using xpath we can acess all the data we need in each node
TweetURL = node.SelectSingleNode("link").InnerText
TweetText = Mid(node.SelectSingleNode("title").InnerText,UNameLen)
TweetText = Linkify(TweetText)
TweetText = Atify(TweetText)
TweetText = Hashify(TweetText)
TweetText = "<a href=""http://twitter.com/athersgeo"" target=""_blank"">@athersgeo</a>: " & TweetText
divMRSS.InnerHtml += "" & TweetText & "<BR><a href=""" & TweetURL & """ target=""_blank"">" & RelativeTime(node.SelectSingleNode("pubDate").InnerText) & "</a><BR><HR>"
i = i + 1
If i = 5 then
Exit For
End if
Next
End Sub
Is there something that I'm not closing/disposing of that's sucking up connections? Or have I just coded something blindingly stupid? (Which wouldn't be the first time!)
Upvotes: 1
Views: 114
Reputation: 535
400 Bad Request is associated with HTTP. From your code it seems the only HTTP request is to load the xmlDocument rssDoc.Load("http://twitter.com/statuses/user_timeline/athersgeo.rss")
.
But you mention that - the rss feed on Twitter is just fine - how could you ensure that?
As suggested in this blog you could use Fiddler to explore your request going out to twitter - http://blogs.msdn.com/b/hakane/archive/2009/06/30/investigating-http-400-bad-request-errors-in-web-access.aspx
Upvotes: 1