有人能告诉我为什么我在经典的asp中没有得到MSXML2.ServerXMLHTTP.6.0的响应吗?

时间:2013-05-15 13:38:10

标签: xml asp-classic rss response serverxmlhttp

有人可以告诉我为什么我没有收到回复吗?

<%
    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")
%>

我正在尝试将来自twitter api的rss feed xml发送到我的服务器上,我可以使用客户端代码操作它。有人能告诉我为什么我没有使用此代码获取Feed吗?

1 个答案:

答案 0 :(得分:4)

成功!问题出在这里:

  1. 我回到问号的原因是它是二进制格式。
  2. ResponseText导致跨浏览器中的doctype出现编码问题(我认为这就是为什么Chrome中没有样式,并且网页上的IE中有样式)
  3. 代理没有必要。
  4. MSXML2.ServerXMLHTTP.6.0也会导致Atom RSS feed出现编码错误。
  5. 我使用了ResponseBody和Microsoft.XMLHTTP:

    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