有人可以告诉我为什么我没有收到回复吗?
<%
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吗?
答案 0 :(得分:4)
成功!问题出在这里:
ResponseText
导致跨浏览器中的doctype出现编码问题(我认为这就是为什么Chrome中没有样式,并且网页上的IE中有样式)我使用了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