找回密码
 加入
搜索
查看: 3503|回复: 8

microsoft.xmlhttp 乱码有解决方法吗?

[复制链接]
发表于 2008-8-2 18:38:59 | 显示全部楼层 |阅读模式
$varh 返回中文都是乱码,请教高手在au3里有解决方法吗?
$oHTTP = ObjCreate("microsoft.xmlhttp")
$oHTTP.Open("get", "http://www.baidu.com", False)
$oHTTP.Send()
$varh=$oHTTP.responseText
MsgBox(0,0, $varh)
发表于 2008-8-2 18:53:11 | 显示全部楼层
是有乱码问题,按网上的解决办法是用VBS函数转换。


<% 
Function bytes2BSTR(arrBytes) 
strReturn = "" 
arrBytes = CStr(arrBytes) 
For i = 1 To LenB(arrBytes) 
ThisCharCode = AscB(MidB(arrBytes, i, 1)) 
If ThisCharCode < &H80 Then 
strReturn = strReturn & Chr(ThisCharCode) 
Else 
NextCharCode = AscB(MidB(arrBytes, i+1, 1)) 
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode)) 
i = i + 1 
End If 
Next 
bytes2BSTR = strReturn 
End Function 

Dim objXMLHTTP, xml 
Set xml = Server.CreateObject("Microsoft.XMLHTTP") 

xml.Open "GET", "http://www.baidu.com/index.html", False 
xml.Send 

Response.Write bytes2BSTR(xml.responseBody) 

Set xml = Nothing 
%>


 楼主| 发表于 2008-8-2 18:57:58 | 显示全部楼层
三恨能否帮忙写个AU3函数,直接调用就方便了。
发表于 2008-8-2 19:36:58 | 显示全部楼层
但是au3不支持 Microsoft.XMLHTTP的 .responseBody 属性
发表于 2008-8-2 19:37:38 | 显示全部楼层
还是用_INetGetSource
发表于 2008-12-25 13:52:30 | 显示全部楼层
NO。。。我找到解决办法了。哈。
发表于 2008-12-25 19:59:02 | 显示全部楼层
哈哈,我收回我的话,还是有办法的!


$http=ObjCreate("Microsoft.XMLHTTP")
$http.open("get","http://www.baidu.com","false")
$http.setRequestHeader("Content-Type","text/HTML")
$http.send()
$b=bytes2BSTR($http.responseBody)
MsgBox(0,"",$b)

;bytes2BSTR($str) 将返回的网页文字不存在乱码
;必须是 $http.responseBody
;==============================================

Func bytes2BSTR($str)
Local $code
$code&='Function bytes2BSTR(arrBytes)'&@CRLF  
$code&='strReturn = "" '&@CRLF
$code&='arrBytes = CStr(arrBytes)'&@CRLF  
$code&='For i = 1 To LenB(arrBytes)'&@CRLF  
$code&='ThisCharCode = AscB(MidB(arrBytes, i, 1))'&@CRLF  
$code&='If ThisCharCode < &H80 Then'&@CRLF  
$code&='strReturn = strReturn & Chr(ThisCharCode)'&@CRLF  
$code&='Else'&@CRLF  
$code&='NextCharCode = AscB(MidB(arrBytes, i+1, 1))'&@CRLF  
$code&='strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))'&@CRLF  
$code&='i = i + 1'&@CRLF  
$code&='End If'&@CRLF  
$code&='Next'&@CRLF  
$code&='bytes2BSTR = strReturn'&@CRLF  
$code&='End Function'&@CRLF
$VBS = ObjCreate("ScriptControl")
$VBS.language = "vbscript"
$VBS.addcode($code)
Return $vbs.run("bytes2BSTR",$str)
EndFunc










[ 本帖最后由 gto250 于 2009-2-14 12:27 编辑 ]
发表于 2008-12-25 20:19:51 | 显示全部楼层
有必要这么复杂吗?

看我的。多简单。哈。

http://www.autoitx.com/forum.php?mod=viewthread&tid=4443&extra=page%3D1&frombbs=1
发表于 2009-7-1 16:41:26 | 显示全部楼层
非常的好,大家的各有各用哈
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-23 01:30 , Processed in 0.075773 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表