visualbasic6.0的一個(gè)模塊方法,使用XMLHTTP實(shí)現(xiàn)Post與Get功能,一個(gè)老代碼了,替代Inet控件,實(shí)現(xiàn)數(shù)據(jù)通訊,5月的時(shí)候修改過(guò),作者不是我本人。模塊代碼:
011 |
Public Function GetData( ByVal Url As String , ByVal DataStic As DataEnum) As Variant |
014 |
Dim XMLHTTP As Object |
018 |
Set XMLHTTP = CreateObject( "Microsoft.XMLHTTP" ) |
020 |
XMLHTTP.Open "get" , Url, True |
023 |
While XMLHTTP.ReadyState <> 4 |
030 |
DataS = XMLHTTP.ResponseText |
034 |
DataB = XMLHTTP.ResponseBody |
036 |
Case ResponseBody + ResponseText |
038 |
DataS = BytesToStr(XMLHTTP.ResponseBody) |
045 |
Set XMLHTTP = Nothing |
051 |
Public Function PostData( ByVal StrUrl As String , ByVal StrData As String , ByVal DataStic As DataEnum) As Variant |
054 |
Dim XMLHTTP As Object |
058 |
Set XMLHTTP = CreateObject( "Microsoft.XMLHTTP" ) |
060 |
XMLHTTP.Open "POST" , StrUrl, True |
061 |
XMLHTTP.setRequestHeader "Content-Length" , Len(PostData) |
062 |
XMLHTTP.setRequestHeader "CONTENT-TYPE" , "application/x-www-form-urlencoded" |
063 |
XMLHTTP.send (StrData) |
065 |
Do Until XMLHTTP.ReadyState = 4 |
072 |
DataS = XMLHTTP.ResponseText |
076 |
DataB = XMLHTTP.ResponseBody |
078 |
Case ResponseBody + ResponseText |
080 |
DataS = BytesToStr(XMLHTTP.ResponseBody) |
087 |
Set XMLHTTP = Nothing |
093 |
Function BytesToStr( ByVal vIn) As String |
095 |
For i = 1 To LenB(vIn) |
096 |
ThisCharCode = AscB(MidB(vIn, i, 1)) |
097 |
If ThisCharCode < &H80 Then |
098 |
strReturn = strReturn & Chr(ThisCharCode) |
100 |
NextCharCode = AscB(MidB(vIn, i + 1, 1)) |
101 |
strReturn = strReturn & Chr( CLng (ThisCharCode) * &H100 + CInt (NextCharCode)) |
105 |
BytesToStr = strReturn |
該文章在 2014/3/24 12:47:17 編輯過(guò)