请教......idhttp的问题,如何扑获返回值,并是网页重定向???
请教怎么使用Idhttp控件。
我用delphi写了一个网站登陆验证页面,登陆时总是出现HTTP 1.1/302 Found,然后我跟踪的返回值ResponseStream.DataString='',我只想获得一个验证值,不知道为何网页总是转向default.aspx, 而不是转向我希望的main.aspx,如何解决?
附验证代码:
function TFormLogin.LoginOK: Boolean;
var
IdHTTP1 :TIdHTTP;
sParams1,sParams2,sParams3 :String;
LoginInfo :TStrings;
ResponseStream :TStringStream;
begin
PostURL:="http://172.31.5.103/longin.aspx"
Result :=false;
IdHTTP1 := TIdHTTP.Create(nil);
LoginInfo:= TStringList.Create;
ResponseStream := TStringStream.Create('');
sParams1 := '?username='+ user;
sParams2 := 'password='+ pass;
LoginInfo.Clear;
LoginInfo.Add(sParams1);
LoginInfo.Add(sParams2);
try
IdHTTP1.Request.ContentType:='application/x-www-form-urlencoded';
IdHTTP1.Request.ContentLength:=length(LoginInfo.Text);
IdHTTP1.Post(PostURL, LoginInfo, ResponseStream);
if pos('验证通过 ',ResponseStream.DataString)>0 then
Result:=True
except
on e:Exception do
MessageBox(e.Message,'提示信息',48);
end;
IdHTTP1.Free;
LoginInfo.Free;
ResponseStream.Free;
end;
============================
提交和返回数据:
POST /login.aspx?un=111&up=2228 HTTP/1.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
Host: 172.31.5.103
Accept: text/html, */*
User-Agent: Mozilla/3.0 (compatible; Indy Library)
HTTP/1.1 302 Found
Connection: keep-alive
Date: Wed, 05 Apr 2006 00:28:35 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Location: /pzlq2005/default.aspx
Set-Cookie: ASP.NET_SessionId=55ioo345lzbxdrmyyv15ip55; path=/
Cache-Control: private
Content-Type: text/html; charset=gb2312
Content-Length: 139
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href='/default.aspx'>here</a>.</h2>
</body></html>