使用IdHttp自动登陆网页问题.... ( 积分: 200 )

  • 主题发起人 主题发起人 zhuxd
  • 开始时间 开始时间
Z

zhuxd

Unregistered / Unconfirmed
GUEST, unregistred user!
本人做一个用idhttp自动登陆公司内部网站的工具,用Get没办法登陆它,问题是现在用post也没办法登陆,以前可以...不知道对方改动了什么东西...
服务器端不在本地, 是用Apache架设的, 可能是用PHP写的网页. (小日本搞的)
例子如下:
procedure TForm1.Button1Click(Sender: TObject);
const
URL='http://arcwebdb.yokohama.hitachi.co.jp/webdspovs/login.do'; //内部网址
var
P:TStringList;
begin
P:=TStringList.Create;
P.Add('userid=用户名');
P.Add('passwd=密码');
P.Add('ipaddress=170.90.80.1');
try
try
IdHTTP1.Post(URL,P,Response);
showmessage('登陆成功.');
except
showmessage('登陆失败');
end;
finally
P.Free;
end;
end;
运行后提示403错误. 若把URL的值给成其他的网址,如'http://www.baidu.com',参数也相应改动,程序不会出错.
网页源代码我用遨游浏览器显示如下:
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html lang="zh">
<head>
<META http-equiv="Content-Type" content="text/html; charset=MS932">
<META name="GENERATOR" content="Eclipse">
<title>Login</title>
</head>
<body bgcolor="#ccccff">
<P align="center"><B><FONT size="+3" color="#336633">
<IMG src="Image/title.gif" width="636" height="33" border="0" alt="Web Document Search and Print System Version2.0">
</FONT></B></P>
<HR size="5">
<P align="center"><IMG src="Image/login.gif" width="129" height="37" border="0" alt="Login"></P>
<P align="center"><FONT size="+2" color="#000000"><B>Please Input USERID and PASSWORD.</B></FONT></P>
<CENTER>
<form name="loginForm" method="post" action="/webdspovs/login.do" enctype="application/x-www-form-urlencoded">
<TABLE height="62" width="237" cellpadding="5" cellspacing="0">
<TBODY>
<TR>
<TD align="right"><FONT size="+2" color="#000000" >USERID</FONT></TD>
<TD><input type="text" name="userid" maxlength="12" size="15" value="" onfocus="window.status = 'Please Input USERID.';"></TD>
</TR>
<TR>
<TD align="right"><FONT size="+2">PASSWORD</FONT></TD>
<TD><input type="password" name="passwd" maxlength="10" size="15" value="" onfocus="window.status = 'Please Input PASSWORD.';"></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<input type="submit" value="Login"> <input type="reset" value="Clear">
<BR>
</CENTER>
<input type="hidden" name="ipaddress" value="170.95.82.3">
</form>
<script type="text/javascript" language="JavaScript">
<!--
var focusControl = document.forms["loginForm"].elements["userid"];
if (focusControl.type != "hidden" && !focusControl.disabled) {
focusControl.focus();
}
// -->
</script>
<BR>
<BR>
<BR>
<a href="index.jsp"><IMG src="Image/button/gotoTop.gif" border="0" alt="Go To Top"></a>
<HR size="5">
</body>
</html>

TNND,小日本在挑战我们的智慧,上次改密码,改网址,改权限,这次不知道改了什么东西,让我们大家一起想办法,搞死他的服务器....
 
本人做一个用idhttp自动登陆公司内部网站的工具,用Get没办法登陆它,问题是现在用post也没办法登陆,以前可以...不知道对方改动了什么东西...
服务器端不在本地, 是用Apache架设的, 可能是用PHP写的网页. (小日本搞的)
例子如下:
procedure TForm1.Button1Click(Sender: TObject);
const
URL='http://arcwebdb.yokohama.hitachi.co.jp/webdspovs/login.do'; //内部网址
var
P:TStringList;
begin
P:=TStringList.Create;
P.Add('userid=用户名');
P.Add('passwd=密码');
P.Add('ipaddress=170.90.80.1');
try
try
IdHTTP1.Post(URL,P,Response);
showmessage('登陆成功.');
except
showmessage('登陆失败');
end;
finally
P.Free;
end;
end;
运行后提示403错误. 若把URL的值给成其他的网址,如'http://www.baidu.com',参数也相应改动,程序不会出错.
网页源代码我用遨游浏览器显示如下:
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html lang="zh">
<head>
<META http-equiv="Content-Type" content="text/html; charset=MS932">
<META name="GENERATOR" content="Eclipse">
<title>Login</title>
</head>
<body bgcolor="#ccccff">
<P align="center"><B><FONT size="+3" color="#336633">
<IMG src="Image/title.gif" width="636" height="33" border="0" alt="Web Document Search and Print System Version2.0">
</FONT></B></P>
<HR size="5">
<P align="center"><IMG src="Image/login.gif" width="129" height="37" border="0" alt="Login"></P>
<P align="center"><FONT size="+2" color="#000000"><B>Please Input USERID and PASSWORD.</B></FONT></P>
<CENTER>
<form name="loginForm" method="post" action="/webdspovs/login.do" enctype="application/x-www-form-urlencoded">
<TABLE height="62" width="237" cellpadding="5" cellspacing="0">
<TBODY>
<TR>
<TD align="right"><FONT size="+2" color="#000000" >USERID</FONT></TD>
<TD><input type="text" name="userid" maxlength="12" size="15" value="" onfocus="window.status = 'Please Input USERID.';"></TD>
</TR>
<TR>
<TD align="right"><FONT size="+2">PASSWORD</FONT></TD>
<TD><input type="password" name="passwd" maxlength="10" size="15" value="" onfocus="window.status = 'Please Input PASSWORD.';"></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<input type="submit" value="Login"> <input type="reset" value="Clear">
<BR>
</CENTER>
<input type="hidden" name="ipaddress" value="170.95.82.3">
</form>
<script type="text/javascript" language="JavaScript">
<!--
var focusControl = document.forms["loginForm"].elements["userid"];
if (focusControl.type != "hidden" && !focusControl.disabled) {
focusControl.focus();
}
// -->
</script>
<BR>
<BR>
<BR>
<a href="index.jsp"><IMG src="Image/button/gotoTop.gif" border="0" alt="Go To Top"></a>
<HR size="5">
</body>
</html>

TNND,小日本在挑战我们的智慧,上次改密码,改网址,改权限,这次不知道改了什么东西,让我们大家一起想办法,搞死他的服务器....
 
此网址用浏览器可以正常打开,也能正常登陆.网址是没有错的.
 
转贴:

Using Indy idHTTP to post binary and text
Note: Click Title to view in Edit Box for easier copying.

This is a small example of using post to send data to web server.

There is two different ways to do this operation.

uses idGlobal;

Example 1:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Const
CRLF = #13#10;
Var
aStream: TMemoryStream;
Params: TMemoryStream;
S: String;
begin
aStream := TMemoryStream.create;
Params := TMemoryStream.Create;

HTTP.Request.ContentType := 'multipart/form-data;
boundary=-----------------------------7cf87224d2020a';

try
S := '-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="file1"; filename="c:abc.txt"' +
CRLF +
'Content-Type: text/plain' + CRLF + CRLF +
'file one content. Contant-Type can be application/octet-stream or if
you want you can ask your OS fot the exact type.' + CRLF +
'-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="sys_return_url2"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf87224d2020a--';

Params.Write(S[1], Length(S));

with HTTP do begin
try
HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
<----------------------------------------------------------------->


Example 2:
<----------------------------------------------------------------->
procedure TForm1.SendPostData;
Var
aStream: TMemoryStream;
Params: TStringStream;
begin
aStream := TMemoryStream.create;
Params := TStringStream.create('');
HTTP.Request.ContentType := 'application/x-www-form-urlencoded';

try
Params.WriteString(URLEncode('sys_return_url=' + 'helo1' + '&'));
Params.WriteString(URLEncode('sys_return_url=' + 'helo2'));
with HTTP do begin
try
HTTP.Post('http://www.mydomain.com/postexampe.cgi', Params,
aStream);
except
on E: Exception do
showmessage('Error encountered during POST: ' + E.Message);
end;
end;
aStream.WriteBuffer(#0' ', 1);
showmessage(PChar(aStream.Memory));
except
end;
end;
<----------------------------------------------------------------->

As you can see there is a difference in the way post stream is constructed
and the ContentType. In the first example ContentType is
"multipart/form-data; boundary=-----------------------------7cf87224d2020a"
and this boundary is used to separate different parameters.

In the second example the ContentType is
"application/x-www-form-urlencoded".
In this case the paremeteras are passed in the form

ParamName=ParamValue&ParamName=ParamValue

Note that the Pramaeters in the second form must be URL encoded.

Where these two formats of post information are used?

The first one is used when you have binary data to post and the second one
is when you are going to post only text fields.

Doychin - Team Indy
doychin@dsoft-bg.com
WebPage: http://www.nevrona.com/indy/
 
to skadon:

HTTP.Request.ContentType := 'multipart/form-data;
boundary=-----------------------------7cf87224d2020a';

try
S := '-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="file1"; filename="c:abc.txt"' +
CRLF +
'Content-Type: text/plain' + CRLF + CRLF +
'file one content. Contant-Type can be application/octet-stream or if
you want you can ask your OS fot the exact type.' + CRLF +
'-----------------------------7cf87224d2020a' + CRLF +
'Content-Disposition: form-data; name="sys_return_url2"' + CRLF + CRLF +
'hello2' + CRLF +
'-----------------------------7cf87224d2020a--';

这段字符串是什么东西? 为什么后面都要加上7cf87224d2020a?
第2种方法,我之前试过了,好象不行...
'http://arcwebdb.yokohama.hitachi.co.jp/webdspovs/index.jsp'
这个网址不需要任何参数,用idhttp的get,和post也不行....好象idhttp被屏蔽了样子...
会不会是它用了什么加密或什么协议之类的,要嘛说idhttp不支持PHP....
 
这段字符串是IE或者http编码后发送到服务器的实际数据结构,不用我们处理。
如果是idhttp被屏蔽了,可以修改idhttp的User-Agent来试试,需要改源代码的
仍不行的话就再看看打开这个URL的时候服务器是不是在Cookie做了记录
 
我认为他是在cookie中做了记录...
我打开'http://arcwebdb.yokohama.hitachi.co.jp/webdspovs/index.jsp'地址,
单击Start按键后,页面切换到
'http://arcwebdb.yokohama.hitachi.co.jp/webdspovs/start.do;jsessionid=4FFC4D9CD452477EABC4960CFB0BB46E'地址(这个地址就是我们登陆的那个页面,需要输入用户名密码),
我认为后面的'jsessionid=4FFC4D9CD452477EABC4960CFB0BB46E'一串应该就是cookie吧...不知道idhttp中怎么获取这串信息,并加以使用.
能给个例子吗???谢谢了。...
 
在IdHTTP1.Response.里面取得返回的头信息,提交的时候在IdHTTP1.Request设置头信息
如果有转向,设置IdHTTP1.RedirectMaximum:=1;
 
procedure TForm1.Button1Click(Sender: TObject);
const URL='http://arcwebdb.yokohama.hitachi.co.jp/webdspovs/index.jsp';
var
P:TStringList;
Response : TStringStream;
begin
P:=TStringList.Create;
Response := TStringStream.Create('');
{P.Add('userid=zhu');
P.Add('passwd=k3347');
P.Add('ipaddress=170.95.82.3');}
memo1.Lines.Clear;
try
Try
idHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHttp1.get(URL);
//IdHTTP1.Post(URL,P,Response);
Memo1.Lines.Text :='ok';
except
Memo1.Lines.Text :='error';
end;
Memo1.Lines.Add('Respoinsetext='+IdHttp1.ResponseText);
finally
P.Free;
Response.Free ;
end;
end;
是这样写吗?
我用get或post都不行,它返回
error
Respoinsetext=HTTP/1.1 403 Forbidden
信息.....
 
我看你输入的IP地址与网页的IP地址不一样,可能,他的网站记录有那些IP地址可以登录的信息。
 
to wiseyao:
你是说170.90.80.1和170.95.82.3的IP吗?
呵呵,那是我贴帖时随便改一个的,其实我是用同一个IP的.
我用别的网址都可以返回,就是这个网址不行,以前都行的,
我用多线程下载他们的图纸,可能被他们发现了,所以跟我搞鬼......郁闷中....
 
谢谢skadon,问题已经解决,需要设置useragent参数...
 
zhuxd,能否将您最后的代码给小弟发一份呢?小弟也困惑了两天了。
 
后退
顶部