Question

Can someone tell me why I am not getting a response?

<%
    RssURL = "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=nrcGOV"

    Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
    xmlHttp.setProxy 2, "www.proxy.mydomain.com:80"
    xmlHttp.Open "Get", RssURL, false
    xmlHttp.Send()
    myXML = xmlHttp.ResponseText
    myXMLcode = xmlHttp.ResponseXML.xml

    response.Write(myXML)
    response.Write(myXMLcode)
    response.Write("hey")
%>

I am trying to get the rss feed xml from the twitter api onto my server where I can manipulate it with client side code. Can someone tell me why I am not getting the feed with this code?

Was it helpful?

Solution

Success! Here was the problem:

  1. The reason I got back the question mark was that it was in binary format.
  2. ResponseText causes an encoding problem with the doctype in cross browser (which I think is why there are no styles in Chrome and there are styles in IE on the URL itself)
  3. The Proxy wasn’t necessary.
  4. MSXML2.ServerXMLHTTP.6.0 also causes an encoding error on Atom RSS feeds.

I used ResponseBody and Microsoft.XMLHTTP instead:

url = "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=myName"
'xmlHttp.setProxy 2, "www.proxy.mydomain.com:80"

Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.Open "GET", url, False
objHTTP.Send
rss = BinaryToString(objHTTP.ResponseBody)
Response.Write(rss)

Function BinaryToString(byVal Binary)
    '--- Converts the binary content to text using ADODB Stream

    '--- Set the return value in case of error
    BinaryToString = ""

    '--- Creates ADODB Stream
    Dim BinaryStream
    Set BinaryStream = CreateObject("ADODB.Stream")

    '--- Specify stream type
    BinaryStream.Type = 1 '--- adTypeBinary

    '--- Open the stream And write text/string data to the object
    BinaryStream.Open
    BinaryStream.Write Binary

    '--- Change stream type to text
    BinaryStream.Position = 0
    BinaryStream.Type = 2 '--- adTypeText

    '--- Specify charset for the source text (unicode) data
    BinaryStream.CharSet = "UTF-8"

    '--- Return converted text from the object
    BinaryToString = BinaryStream.ReadText
End Function
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top