关于WinHttp.WinHttpRequest.5.1不能获取302重定向的问题

x_craft77 2011-11-16 03:08:57
WinHttp.WinHttpRequest.5.1 封装没有问题
...
winHttp.Option(6) = redirect '为True时,当请求的页面中有跳转时,抓取跳转页面信息.False相反不抓取
...
If winHttp.Status = 200 Or winHttp.status = 302 Then 'Then '服务端响应HTTP 200 即请求成功 加入302处理
...

在以往的应用中也没有遇到问题,但这次使用中,目标页重定向是一个相对路径
Location: /document/datapost.aspx
就碰到问题了,true允许重定向,而WinHttp.WinHttpRequest.5.1却采集不到信息,何故?是因为重定向地址是个相对路径,而WinHttp.WinHttpRequest.5.1本身有这个缺陷吗?
...全文
917 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
onetwofree 2011-11-18
  • 打赏
  • 举报
回复
Set winhttp=Server.CreateObject("winhttp.winhttprequest.5.1")
winhttp.Option(6)=0
hefeng_aspnet 2011-11-18
  • 打赏
  • 举报
回复
详解:
<!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>


x_craft77 2011-11-16
  • 打赏
  • 举报
回复
自已顶一下

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧