MSXML2.ServerXMLHTTP 取返回页面值的奇怪的问题?
ycwww 2017-05-12 11:29:34 求asp 获取这个 新浪 短网址 的源码:
http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=http://www.163.com
经过测试:
用 Gethttppage(“http://www.163.com”) 取值正常
但是用 Gethttppage("http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=http://www.163.com")
没有返回值。
但是新浪的这个网址直接打开到浏览器又能正常显示数据。
==== 之前一直正常使用的,今天发现获取不到了,用到的函数如下 ====
function Gethttppage(url)
on error resume next
dim adxmlhttp
set adxmlhttp = Server.createobject("MSXML2.ServerXMLHTTP")
adxmlhttp.open "get",url,false
On Error Resume Next
adxmlhttp.send()
if (adxmlhttp.readystate <> 4) Or (adxmlhttp.Status <> 200) then exit function
gethttppage = Bytes2bStr(adxmlhttp.responsebody)
set adxmlhttp = nothing
End function
function Bytes2bStr(vin)
on error resume next
Dim BytesStream,StringReturn
Set BytesStream = Server.CreateObject("adodb.stream")
BytesStream.Type = 2
BytesStream.Open
BytesStream.WriteText vin
BytesStream.Position = 0
BytesStream.Charset = "gb2312"
BytesStream.Position = 2
StringReturn =BytesStream.ReadText
BytesStream.close
Set BytesStream = Nothing
Bytes2bStr = StringReturn
End function