IdHttp实现自动登录网页出现的问题 ( 积分: 300 )

  • 主题发起人 晓风月
  • 开始时间

晓风月

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button2Click(Sender: TObject);
const
BaseURL = 'http://192.168.2.25/'; //论坛所在地址
UserName = 'sa'; //登录用户名
Password = '123'; //登录密码
var
Params: TStrings;
HTML: String;
MD5Pass: String;
ret:tstringstream;
begin
Params:=TStringList.Create;
ret:=TStringStream.Create('');
try
Params.Clear;
Params.add('txt_user='+UserName);
Params.Add('txt_password='+Password);

IDHttp.HandleRedirects := true;
IdHTTP.request.contenttype:='application/x-www-form-urlencoded';

IdHTTP.Request.Referer := BaseURL + 'test/login.asp';
IdHTTP.Post(BaseURL+'test/login_check.asp',Params,ret);

HTML:=ret.datastring;
Memo1.Lines.Text := HTML;
if Pos(BASEURL+'login.asp',HTML)=0 then
begin
ShowMessage('登录失败');
Exit;
end;
finally
Params.Free;
end;
end;

------------------
asp代码说明:
登录后提交的页面是:login_check.asp
在这个页面中我的测试代码简单的只有以下:
username=trim(Request.Form("txt_user"))
response.write "username=" & username
password=trim(Request.Form("txt_password"))
response.write "password=" & password
----------------------------
问题:按正常应该是username=sa
password=123

但实际遇到的问题是username=satxt_password=123
password=
不解呀!!!!!!为什么我传的是两个参数,但程序却把两个参数当作了一个参数?
 
关注一下 以前我也想搞得
 
我以前也写过一个登录WEB页面的过程,这个是可以的.
处理的关键是在WEB页面程序中.
try
http := TIdHTTP.Create;
strLst := TStringList.Create;
ReturnLst := TStringList.Create;
try
strLst.Values['UserID'] := UserID;
strLst.Values['Password'] := Password;
http.Request.ContentType := 'application/x-www-form-urlencoded';
ReturnVal := http.Post(URL + 'login.aspx', strLst);
ReturnLst.Text := ReturnVal;
for i := 0 to ReturnLst.Count - 1 do
begin
if UpperCase(ReturnLst.Names) = 'RESULT' then
begin
if UpperCase(ReturnLst.ValueFromIndex) = 'OK' then
begin
Result := LongBool(True);
Break;
end;
end;
end;
finally
http.Free;
strLst.Free;
ReturnLst.Free;
end;
 
休息了几分钟,总算得以解决,看来还是要注意调整。

问题出在DELPHI代码:
这是原来代码的:
Params.add('txt_user='+UserName);
Params.Add('txt_password='+Password);
修改为以下代码(仅在第二个参数加了一个&):
Params.add('txt_user='+UserName);
Params.Add('&txt_password='+Password);
 
to:xxj0828
方便留个联系方式交流一下吗?最近正在进行该方面的研发,有些问题希望得到你的帮助。
--------------------------
PHP登录界面中有以下代码,请分析作用,怎样绕过:
<script language=&quot;JavaScript&quot;>
function run(code)
{
code=unescape(code);
var c=String.fromCharCode(code.charCodeAt(0)+(code.length%13));
for(var i=1;i<code.length;i++){
c+=String.fromCharCode(code.charCodeAt(i)+(c.charCodeAt(i-1)%13));
}
return c;
}
eval(run(&quot;%02l%60l%16fc%147%17h%5BphfUnck%24ZjhFag%6034%19FejgXYj%5D%18%189%15h%5BphfUnck%24e%5DhaiaaY%24mcEdpch9_mZ%1E%28%1E4%1Ah%5BphfUnck%24nsZhBVhaiaaY%2

4mcEdpch9_mZ%1E%289%03l%60l%16n%5Cir%5Donr%167%17h_m%1E%3E%5EnY%1E%289%03l%60l%16tjg_%167%17n%5Cir%5Donr%24%60YjHcl%60pjg_Ee%5BhZj%1C%28-..2%03iZjHcl%60ent%1

C%21%5Cf%5Cmm%60dn%22ek%60%5Dm%60dkc%29ec%22o%60fqe%167%17fc%16%24%2C%26%27%209%03iZjHcl%60ent%1C%21%5Cf%5Cmm%60dn%22ek%60%5Dm%60dkc%29mn%29o%60fqe%167%17tjg

_%18%24%2C%26%27%209%03iZjHcl%60ent%1C%21%5Cf%5Cmm%60dn%22ek%60%5Dm%60dkc%29dw%29o%60fqe%167%17-+/%26%18%24%2C%26%27%209%03&quot;));
</script>
 
对于我前面这段PHP代码,我知是把asc码值转换成字符,但最关键我想知道他在登录页面中的作用是什么,写程序的人这样做的目的是什么?我用自动登录要怎样绕过去。
 
问题在进一步发展:
刚刚我解析了这段JSP代码,得到如下字符:
var lg = navigator.appName==&quot;Netscape&quot; ? navigator.language.toLowerCase() : navigator.userLanguage.toLowerCase();
var thishour = new Date();
var zone = thishour.getTimezoneOffset()/60;
setTimeout(&quot;document.loginform.lg.value = lg&quot;,100);
setTimeout(&quot;document.loginform.tz.value = zone&quot;,100);
setTimeout(&quot;document.loginform.kz.value = 3721&quot;,100);

但问题还是想知,作者这样做的目的,我用自动登录要怎样绕过去。
 
已经解决,谢谢大家参入。有这方面问题的可以来问我了。
 
求助啊 前辈(我是新手)~~~
我按照你的方法 做了个远程登陆的可是弄了一天也没弄出来个结果来[:(]
这是源代码
procedure TForm1.Button1Click(Sender: TObject);
const
BaseUrl='http://www.xiaonei.com/';
UserName='已经注册的邮箱地址';
Password='邮箱密码' ;
Var
Params: TStrings;
HTML:String;
MD5Pass:String;
ret:tstringstream;
begin
Params:=TStringList.Create;
ret:=TStringStream.Create('');
try
Params.Clear;
Params.Add('email='+UserName);
Params.Add('&amp;password'+Password);
Idhttp1.HandleRedirects:= true;
Idhttp1.Request.ContentType:='application/x-www-form-urlencoded';
Idhttp1.Request.Referer:=BaseUrl+'/Login.do';
Idhttp1.Post(BaseUrl+'/Login.do',Params,ret);
HTML:=ret.DataString;
Memo1.Lines.Text:=HTML;
if Pos(BaseUrl+'/Home.do',HTML)=0 then
begin
ShowMessage('登陆失败');
Exit;
end
finally
Params.Free;
end;
这样就完了? 可是怎么知道是成功还是失败了呢?那个showmessage根本没用,还有我用了个Webbrowser 结果显示没登陆上.你的第一个帖子说的
asp代码说明:
登录后提交的页面是:login_check.asp
在这个页面中我的测试代码简单的只有以下:
username=trim(Request.Form(&quot;txt_user&quot;))
response.write &quot;username=&quot; &amp; username
password=trim(Request.Form(&quot;txt_password&quot;))
response.write &quot;password=&quot; &amp; password
这些是干什么用的?
到底怎么回事啊~~期待回复~~
 
Webbrowser 肯定显示没有登录,因为你没有构造出COOKIES出来。不要用Webbrowser来判断是否登录成功。你直接检查返回原HTML代码中是否有进入下一个页面链接的代码。有问题到我的主页来交流:swifthorse.javaeye.com
 
你好 刚才去你的主页了,可是我刚注册的,没法在你的主页留言,所以只能在这儿再麻烦你了,可不可以把你做得这个源码打包给我发来,如果方便的话?我实在是弄不懂了这里面到底怎么个登陆 希望你得源码能给我启示 我的邮箱是cuiyi1021@126.com
谢谢
 
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>
<html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;>
<head>


<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; />
<link href=&quot;http://static.xiaonei.com/css/main-0702.css?ver=13162.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot; />
<script type=&quot;text/javascript&quot; src=&quot;http://static.xiaonei.com/js/util.js?ver=13155.js&quot;></script>
<script type=&quot;text/javascript&quot; src=&quot;http://static.xiaonei.com/js/prototype.js?ver=13155.js&quot;></script>

<link href=&quot;http://static.xiaonei.com/css/mini.css?10002&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot; />
<title>f !eg= - g;e=</title>
</head>
<body id=&quot;registerpage&quot;>
<div id=&quot;container&quot;>

<div id=&quot;header&quot;>

<style>
#header #logo { top:8px;}
#header #logo a { background:transparent;}
</style>
<h1 id=&quot;logo&quot;><a href=&quot;http://home.xiaonei.com/Home.do&quot; title=&quot;f !eg=&quot;><img src=&quot;http://static.xiaonei.com/img/new-logo.gif&quot; alt=&quot;f !eg=(Logo)&quot;/></a></h1>
</div>

<div id=&quot;sidebar&quot;>
<div id=&quot;loginpanel&quot;>
<dl id=&quot;welcome&quot;>
<dt>e(f !eg=d= e/d;%o<</dt>
<dd>e1g$:h*e71o<d:h'#e(e4gee-&amp;o<</dd>
<dd>efed;,ed:+g'g o<</dd>
<dd>h/d;7d8
h?gh/>o<h.$h/i
这是它返回的代码 是不是a href=&quot;http://home.xiaonei.com/Home.do&quot; 这个就说明登陆成功了? 如果用IE正常登陆的话,地址栏里就会显示的是http://www.xiaonei.com/Home.do
和返回的代码不太一样
 
顶部