假设你的服务器127.0.0.1,asp文件为 index.asp
1.
加入winsock控件,步骤:工程->部件,选择Microsoft WinSock Control 6.0(SP6),确定。Winsok就加到工具箱里了,
Form上添加一个Winsock
2.定义两个公用变量,userName,userScore 存放姓名和成绩
3.发送代码如下
Dim userName As String
Dim userScore As String
Private Sub SendStr() '为姓名成绩赋初值
userName = "wangxin"
userScore = "88"
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 80
Winsock1.Connect
End Sub
Private Sub Winsock1_Connect()
Dim strCommand As String
Dim content As String
content = "name=" & userName & "&score=" & userScore
strCommand = "POST /index.asp HTTP/1.1" + vbCrLf
strCommand = strCommand + "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*" + vbCrLf
strCommand = strCommand + "Accept-Language: zh-cn" + vbCrLf
strCommand = strCommand + "Content-Type: application/x-www-form-urlencoded" + vbCrLf
strCommand = strCommand + "UA-CPU: x86" + vbCrLf
strCommand = strCommand + "Accept-Encoding: gzip, deflate" + vbCrLf
strCommand = strCommand + "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0)" + vbCrLf
strCommand = strCommand + "Host: 127.0.0.1" + vbCrLf
strCommand = strCommand + "Content-Length: " & Len(content) & vbCrLf
strCommand = strCommand + "Connection: Keep-Alive" + vbCrLf
strCommand = strCommand + "cache-Control: no-cache" + vbCrLf + vbCrLf
strCommand = strCommand + content
Winsock1.SendData strCommand
End Sub
---------------------
4.
index.asp的内容
<%@language=vbscript%>
<%Response.Buffer=true%>
<%
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
Set OutStream = FileObject.CreateTextFile(left(server.MapPath("index.asp"),instr(server.MapPath("index.asp"),"index.asp")-1)&"index.txt",true)
OutStream.Write Request("name") & "," & Request("score") '将成绩写入index.txt文件,根据实际自己处理
Outstream.close
%>
温馨提示:答案为网友推荐,仅供参考