asp代码WinHttp.WinHttpRequest.5.1使用例子
来源:asp之家 时间:2010-03-11 21:28:00
<!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" />
<title>无标题文档</title>
<script language="javascript" type="text/javascript">
function getCookie(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) {
var uid = unescape(arr[2]).match(new RegExp("userid=(\\d+)"));
return (uid == null) ? "" : uid[1];
//return uid[1];
}else{
return "";
}
}
/*function sendData(objform)
{
//alert(objform.username);
if (window.ActiveXObject && !window.XMLHttpRequest)
{
window.XMLHttpRequest = function()
{
var MSXML = ['Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP'];
for (var i = 0; i < MSXML.length; i++)
{
try {
return new ActiveXObject(MSXML[i]);
}
catch (e){}
}
return null;
};
}
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET","http://www.baidu.com", false);
xmlHttp.send();
var book = xmlHttp.responseText;
alert(book);
}*/
</script>
<%
Function BytesToBstr(body)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GB2312"
'转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
dim username,password
dim http,url,revalue,data
username = request.Form("username")
password = request.Form("password")
url = "http://www.hf777.com/xxx"
if username = "" or password = "" then
response.Write("不能为空!")
response.end
end if
data = "name="&username&"&pass="&password
Set http = server.CreateObject("WinHttp.WinHttpRequest.5.1")
http.Option(4) = 13056
http.Option(6) = True '为True时,当请求的页面中有跳转时,抓取跳转页面信息.False相反不抓取
http.Open "POST", url, False
http.setrequestheader "Referer","http://localhost/zhbb/default.asp"
http.setrequestheader "User-Agent", "Mozilla/4.0"
http.setrequestheader "Connection", "Keep-Alive"
http.setrequestheader "Content-Length",len(data)
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send data
'revalue = BytesToBstr(http.responsebody)
revalue = http.responseText
response.write(revalue)
response.end
end if
%>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="25" align="right"> 用户名:</td>
<td><input name="username" type="text" class="input_text01" id="username" /></td>
<td width="60" align="right">密码:</td>
<td><input name="password" type="text" class="input_text01" id="password" /></td>
<td > <a href="#" class="underline" onclick="document.form1.submit()" >登录</a> <a href="#" class="underline">注册新用户</a></td>
<td width="330"> </td>
<td align="right">安徽赛区0-3岁宝宝网络投票网站</td>
</tr>
</table>
</form>
</body>
</html>