login.asp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
.STYLE1 {color: #0066CC}
-->
</style>
</head>
<body>
<%
Response.Write "username="&Request("username")&"<br>"
If Request("username") = "xiaoxiao"Then
Session("UserName") = "xiao"
Response.Write "<br>Current:Session(""UserName"")="&Session("UserName")&"<br>"
Response.Write ""
response.cookies("UserName")="test"
Else
Response.Write "验证错误,用户名或密码有误"
End If
response.cookies("Un")="123"
%>
<%
If Session("UserName") = "xiao" Then
Response.Write "<br>HaveLogin"
End If
%>
trylogin.asp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
Function GetResult(urlStr)
Dim xmlHttp
Dim retStr
Set xmlHttp = CreateObject("Msxml2.XMLHTTP") '创建对象
On Error Resume Next '出错处理
xmlHttp.Open "POST", urlStr, False '用POST方式打开连接,异步执行。
xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '上传表单
xmlHttp.Send "username=xiaoxiao&userpwd=111111&usercookies=0" '发送指令
If Err.Number = 0 Then '如果连接正确
retStr = xmlHttp.responseText '等待并获得服务端返回的结果字符串
Else
retStr = "Url not found" '否则返回出错信息
End If
Set xmlHttp = nothing '释放对象 GetResult = retStr '返回结果
Response.Write retStr
End Function
%>
<%
GetResult "http://www.1.com/login.asp"
%>
将这两个文件放在同一个域名下可以测试。
测试结果类似于:
username=xiaoxiao
Current:Session("UserName")=xiao
HaveLogin
出现以上测试结果,说明成功登陆。