VB使用XMLHTTP实现Post与Get
|
admin
2014年3月24日 12:47
本文热度 4792
|
visualbasic6.0的一个模块方法,使用XMLHTTP实现Post与Get功能,一个老代码了,替代Inet控件,实现数据通讯,5月的时候修改过,作者不是我本人。模块代码:
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 编辑过