请教......idhttp的问题,如何扑获返回值,并是网页重定向???

xeonfeng 2006-04-05 09:48:02
请教怎么使用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>
...全文
543 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xeonfeng 2006-04-13
  • 打赏
  • 举报
回复
问题基本解决了,谢谢大家

请大家解决另外一个问题
http://community.csdn.net/Expert/topic/4683/4683359.xml?temp=.8455164
51one 2006-04-09
  • 打赏
  • 举报
回复
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2071973
这个应该会对楼主有所帮助
xeonfeng 2006-04-08
  • 打赏
  • 举报
回复
还是问号的问题,用下面代码总是不成功:
PostURL:="http://172.31.5.103/longin.aspx"
LoginInfo.Clear;
LoginInfo.Add('username='+ '123';);
LoginInfo.Add('password='+ '456');
IdHTTP1.Post(PostURL, LoginInfo, ResponseStream);
==============================
如果我把PostURL直接改成我需要用http://192.168.0.3/longin.aspx?username=123&password=456,问题就解决了,请问,访问页面时‘?’问号如何处理,用上面代码中的方法,最后请求的字符时什么,如何才能拼成需要的URL,???
cdsun 2006-04-07
  • 打赏
  • 举报
回复
up
xeonfeng 2006-04-06
  • 打赏
  • 举报
回复
登陆时在IE地址栏里面应该是http://192.168.0.3/longin.aspx?username=123&password=456,请问其中的问好“?”,我应该放在哪里???
放在PostURL最后:
    PostURL:="http://172.31.5.103/longin.aspx"
还是参数最前面:
    sParams1 := '?username='+ user;
xeonfeng 2006-04-06
  • 打赏
  • 举报
回复
顶一下!
问题还没有解决,先谢谢楼上的两位!

不知为何
if pos('main.aspx',ResponseStream.DataString)>0 then
Result:=True
总不能返回真!!!
clasj 2006-04-06
  • 打赏
  • 举报
回复
不用要'?'和'&'了
postren 2006-04-05
  • 打赏
  • 举报
回复
参考
procedure TForm1.Button1Click(Sender: TObject);
var
ret: TStringStream;
FmyParams: TStringList;
I: Integer;
IdHTTP1 :TIdHTTP;
begin
FmyParams := TStringList.Create;
ret := TStringStream.Create('');
IdHttp1 := TIdHttp.Create(nil);
try
with FmyParams do
begin
Clear;
Add('para1=123);
Add('para2=456');
end;
try
IdHttp1.Post('http://www.163.com',FmyParams,ret);
except
On E: Exception do
begin

end;
end;
I := IdHTTP1.ResponseCode;
finally
ShowMessage(ret.DataString);
IdHTTP1.Disconnect;
FmyParams.Free;
ret.Free;
IdHttp1.Free;
end;
end;

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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