主要用了ajax程序核心组件XMLHTTP
'客户端程序
Function SendTo(Url, Msg)
Dim XmlHttp As Object
Static loops As Integer
loops = loops + 1
If loops = 5 Then '进行五次的发送尝试
Exit Function
End If
On Error Resume Next
Set XmlHttp = CreateObject("Msxml2.XMLHTTP")
If Not IsObject(XmlHttp) Then
Set XmlHttp = CreateObject("Microsoft.XMLHTTP")
If Not IsObject(XmlHttp) Then Exit Function
End If
XmlHttp.open "POST", Url, False
XmlHttp.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded"
XmlHttp.Send URLEncoding("Content=" & Msg)
If XmlHttp.Status <> 200 Then
Set XmlHttp = Nothing
DoEvents
SendTo Url, Msg '没成功继续发送
Else
MsgBox XmlHttp.responseText
Set XmlHttp = Nothing
Exit Function
End If
End Function
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vstrIn, i, 1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00) / &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function
Private Sub Command1_Click()
SendTo "http://localhost/heart/test.asp", "nnde.blog.163.com"
End Sub
服务端接收程序处理:
test.asp
<%
response.Charset="GB2312"
msg=request.form("Content")
if msg<>"" then
response.write msg
set fso=CreateObject("scripting.filesystemobject")
Set f=fso.createtextfile(server.MapPath("list.txt"))
f.write msg
f.close
set fso=nothing
else
response.write "no msg"
end if
%>
主要用了ajax程序核心组件XMLHTTP
最新推荐文章于 2025-10-22 16:37:08 发布
