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) 是有乱码问题,按网上的解决办法是用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
%>
三恨能否帮忙写个AU3函数,直接调用就方便了。
:face (29): 但是au3不支持 Microsoft.XMLHTTP的 .responseBody 属性 还是用_INetGetSource NO。。。我找到解决办法了。哈。 哈哈,我收回我的话,还是有办法的!
$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 编辑 ] 有必要这么复杂吗?
看我的。多简单。哈。
http://www.autoitx.com/forum.php?mod=viewthread&tid=4443&extra=page%3D1&frombbs=1 非常的好,大家的各有各用哈
页:
[1]