论坛管理员 发表于 2008-8-2 18:38:59

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

$varh 返回中文都是乱码,请教高手在au3里有解决方法吗?
$oHTTP = ObjCreate("microsoft.xmlhttp")
$oHTTP.Open("get", "http://www.baidu.com", False)
$oHTTP.Send()
$varh=$oHTTP.responseText
MsgBox(0,0, $varh)

sanhen 发表于 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函数,直接调用就方便了。
:face (29):

gto250 发表于 2008-8-2 19:36:58

但是au3不支持 Microsoft.XMLHTTP的 .responseBody 属性

gto250 发表于 2008-8-2 19:37:38

还是用_INetGetSource

sanhen 发表于 2008-12-25 13:52:30

NO。。。我找到解决办法了。哈。

gto250 发表于 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








http://lwc.nhome.cn/code/showip.asp

[ 本帖最后由 gto250 于 2009-2-14 12:27 编辑 ]

sanhen 发表于 2008-12-25 20:19:51

有必要这么复杂吗?

看我的。多简单。哈。

http://www.autoitx.com/forum.php?mod=viewthread&tid=4443&extra=page%3D1&frombbs=1

huangke 发表于 2009-7-1 16:41:26

非常的好,大家的各有各用哈
页: [1]
查看完整版本: microsoft.xmlhttp 乱码有解决方法吗?