idhttp登陆网站http/1.1 405错误,有代码,请高手分析

odbc1230 2011-09-14 03:13:47
环境是D7,用idhttp登陆19楼,报http/1.1 405错误,发的数据包貌似没有错误,想不出原因,请教大家,谢谢


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ToolWin, IdCookieManager, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, ExtCtrls;

type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
IdCookieManager1: TIdCookieManager;
ToolBar1: TToolBar;
LoginBtn: TButton;
ToolButton1: TToolButton;
Memo1: TMemo;
Button1: TButton;
ToolButton2: TToolButton;
Timer1: TTimer;
procedure LoginBtnClick(Sender: TObject);
procedure IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.LoginBtnClick(Sender: TObject);
var
Params:TStrings;
res:TStringStream;
Url,Cook_Str:String;
begin
IdHTTP1.ReadTimeout:= 25000;
IdHTTP1.Request.Accept:= 'image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*';
IdHTTP1.Request.AcceptEncoding:= 'gzip, deflate';
IdHTTP1.Request.AcceptLanguage:= 'zh-cn';
IdHTTP1.Request.CacheControl:= 'no-cache';
IdHTTP1.Request.Connection:= 'Keep-Alive';
IdHTTP1.Request.ContentLength:=144;
IdHTTP1.Request.ContentType:= 'application/x-www-form-urlencoded';

Cook_Str:='__utma=92551362.1470865355.1315979220.1315979220.1315979220.1; __utmz=92551362.1315979220.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);';
Cook_Str:=Cook_Str+' Hm_lvt_5185a335802fb72073721d2bb161cd94=1315979210890; __utmb=92551362.1.10.1315979220; __utmc=92551362; Hm_lpvt_5185a335802fb72073721d2bb161cd94=1315979220531; cdb_sid=7280dda0956157fb93a80c5b0f690556; BIGipServerforum_web_pool=100729098.20480.0000';
IdHTTP1.Request.CustomHeaders.Add(Cook_Str);
IdHTTP1.Request.Host:= 'passport.19lou.com';
IdHTTP1.Request.Referer:= 'http://hangzhou.19lou.com/';
IdHTTP1.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)';

Params :=TStringList.Create;
try
Params.Append('autoLogin=1');
Params.Append('eb0478242e3f3dbdbbf7df7566f404c1=d5520ab6f8095f0f72d4847d4b95c633');
Params.Append('login=?');
Params.Append('userName=********');
Params.Append('userPass=********');

try
Url := 'http://passport.19lou.com/login/index/t/normal';
IdHTTP1.HandleRedirects:=True;

res := TStringStream.Create('');

IdHTTP1.Post(Url,Params,res);
UTF8Decode(TStringStream(IdHTTP1.Response.ContentStream).dataString);

Memo1.Lines.Add(res.DataString);


except

end;

finally
Params.Free;
end;


end;

procedure TForm1.IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
Memo1.Lines.Add('****************************(DEBUG开始)***************************');
Memo1.Lines.Add('=======(访问页面)=========');
Memo1.Lines.Add(IdHTTP1.URL.URI);
Memo1.Lines.Add('=======(页面信息)=========');
Memo1.Lines.Add(IdHttp1.ResponseText);
Memo1.Lines.Add('=======(页面反馈)=========');
Memo1.Lines.Add('-------[发送过去的信息]---------------');
Memo1.Lines.AddStrings(IdHTTP1.Request.RawHeaders);
Memo1.Lines.Add('-------[发送过去的自定义信息]---------------');
Memo1.Lines.AddStrings(IdHTTP1.Request.CustomHeaders);
Memo1.Lines.Add('-------[返回回来的信息]---------------');
Memo1.Lines.AddStrings(IdHTTP1.Response.RawHeaders);
Memo1.Lines.Add('-------[返回回来的自定义信息]---------------');
Memo1.Lines.AddStrings(IdHTTP1.Response.CustomHeaders);
Memo1.Lines.Add('=======(页面内容)=========');
Memo1.Lines.Add(UTF8Decode(TStringStream(IdHTTP1.Response.ContentStream).dataString));
Memo1.Lines.Add('***************************(DEBUG结束)***************************');
end;

end.
...全文
617 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mit1208 2011-09-28
  • 打赏
  • 举报
回复
我这里是正确的呀...没有错误!
这是GET中的代码
id="27bbbf00ef356f9e2351357dd3ef4f14" name="27bbbf00ef356f9e2351357dd3ef4f14" value="78493eb41f0cb5ca35e1bd086c0a0d34


这是用Httpanalyzerstd截获的包

POST /login/index/t/normal HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://passport.19lou.com/login/index/t/normal
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
Host: passport.19lou.com
Content-Length: 141
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: cdb_sid=d715056b6adc992137ce7b29a0e39fd6; BIGipServerforum_web_pool=83951882.20480.0000

userName=love&autoLogin=1&userPass=123456&27bbbf00ef356f9e2351357dd3ef4f14=78493eb41f0cb5ca35e1bd086c0a0d34&login=%C1%A2%BC%B4%B5%C7%C2%BC
odbc1230 2011-09-28
  • 打赏
  • 举报
回复
截获的HTTP包里是这样的
39c6bca9fd3c5ee504a2fa0d8c7114bc 4139aec5c2500e28cb74f187a2b29615
用GET获取的网页里包含的值是
id="39c6bca9fd3c5ee504a2fa0d8c7114bc" name="39c6bca9fd3c5ee504a2fa0d8c7114bc" value="b009f1f75d51ded6ca143d472222664d"

ID这一部分是正确的,但是后半部分是不对的。
odbc1230 2011-09-27
  • 打赏
  • 举报
回复
我就是这样截取的,这个参数在这个页面里,只有前面半段,等号后面的值是没有的。
Mit1208 2011-09-27
  • 打赏
  • 举报
回复

document.write('<script type="text/javascript" src="http://js.19louimg.cn/passport/login.js"></script>');
document.write('<div class="nav_uinfo" id="navuinfo"><form id="loginForm" name="loginForm" method="post" action="http://passport.19lou.com/login/index/t/normal" target="_self" onsubmit="return checkdata();"><ul class="loginform"><li><label class="iblock inp_text"><span class="iblock">用户名:</span><input type="text" id="userName" name="userName" /></label><label class="iblock inp_checkbox"><input type="checkbox" name="autoLogin" value="1" checked /></label><a href="http://passport.19lou.com/register/index" target="_blank">申请入住</a></li><li><label class="iblock inp_text"><span class="iblock">密  码:</span><input type="password" name="userPass" id="userPass"/></label><label class="iblock inp_sm"><input type="hidden" id="ca681972f12ff91b56e8e8b5f96345a7" name="ca681972f12ff91b56e8e8b5f96345a7" value="6e74d7c0ff1150bf0c3fc7d8693367bd"/><input type="submit" value="立即登录" name="login" id=login"/></label><a href="http://passport.19lou.com/lostpass/index" target="_blank">找回密码</a></li></ul></form></div>');
function alertErrorLocalTime_getCookie(name) {
var cookie_start = document.cookie.indexOf(name);
var cookie_end = document.cookie.indexOf(";", cookie_start);
return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
function alertErrorLocalTime_setCookie(cookieName, cookieValue, seconds, path, domain, secure) {
var expires = new Date();
expires.setTime(expires.getTime() + seconds);
document.cookie = escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '/')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
}

var mydate = new Date();
var mytimestamp = parseInt(mydate.valueOf() / 1000);
if(Math.abs(mytimestamp - 1317128019) > 86400 && alertErrorLocalTime_getCookie('alertErrorLocalTime')=="") {
alertErrorLocalTime_setCookie("alertErrorLocalTime", mytimestamp, 86400, "/", ".19lou.com", false);
window.alert('注意:\n\n你本地计算机的时间设定与论坛时间相差超过 24 个小时,\n这可能会影响你的正常登录,请调整本地计算机设置。\n\n当前论坛时间是: (GMT +8) 2011-09-27 20:53:39\n如果你认为论坛时间不准确,请与论坛管理员联系。');
}



红色部分不就是你要取的内容嘛?
shuaialang 2011-09-21
  • 打赏
  • 举报
回复
用nmhttp试试
Mit1208 2011-09-20
  • 打赏
  • 举报
回复
你打开http://passport.19lou.com/login/index/t/normal这个页面看下源代码!

var
Response:string;
begin
Response :=idhttp.get('http://passport.19lou.com/login/index/t/normal');
ShowMessage(Response);
end;


看看Response是否有你所要找的字符串????????????????????????????????????????
odbc1230 2011-09-19
  • 打赏
  • 举报
回复
22906fbbd9903dab9e77f627c808b724=aa5334c99185df63172bd0f7489c1757这个参数截取不到啊,这个只有在POST里面和用户名密码一起发送,其他如COOKIE里面都没有。
Mit1208 2011-09-15
  • 打赏
  • 举报
回复
想到了个办法.
你在IDHTTP控件的OnRedirect事件中写代码就可以了
将重定向的地址改为19楼的主页,这样就显示成功登陆主页的源码了.
Mit1208 2011-09-15
  • 打赏
  • 举报
回复
其实你已经登陆上了.出现这个错误只是没有http://passport.19lou.com这个URL所在的网页而已.
我使用XE测试了一下,在POST异常处又POST了一次,
显示的是<dd class="iblock"><strong>你已经处于登录状态 系统自动给予跳转</strong><br><br>
可想而知,刚才POST登陆已经成功了!但是怎么去掉405这个错误我就不知道了.待高人解决吧!
以下是我的代码:

procedure TForm1.Button1Click(Sender: TObject);
const
LoginUrl='http://passport.19lou.com/login/index/t/normal'; //这个是输入账号密码的页面
var
ParStr,ResStream:TStringStream;
begin
ParStr :=TStringStream.Create;
ResStream :=TStringStream.Create('',TEncoding.Default);//网页内容编码 IdHTTP1.HandleRedirects :=True;
with IdHTTP1.Request do
begin
Referer :='http://passport.19lou.com/login/index/t/normal';
ContentType :='application/x-www-form-urlencoded';
UserAgent :='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)';
end;
ParStr.WriteString('userName=********&autoLogin=1'); //账号隐藏了
ParStr.WriteString('&userPass=********'); //密码也隐藏
ParStr.WriteString('&22906fbbd9903dab9e77f627c808b724=aa5334c99185df63172bd0f7489c1757'); //这两串字符在输入账号密码的页面源码中可看到!
ParStr.WriteString('&login=%C1%A2%BC%B4%B5%C7%C2%BC');
try
IdHTTP1.ProtocolVersion :=pv1_1;
IdHTTP1.HTTPOptions:=[hoKeepOrigProtocol];
IdHTTP1.Post(LoginUrl,ParStr);
except
IdHTTP1.Post(LoginUrl,ParStr,ResStream);
end;
ShowMessage(ResStream.DataString);
FreeAndNil(ParStr);
FreeAndNil(ResStream);
end;
odbc1230 2011-09-15
  • 打赏
  • 举报
回复
经过反复的测试,22906fbbd9903dab9e77f627c808b724=aa5334c99185df63172bd0f7489c1757这组参数应该是日期什么的,如果不用当天最新的,就会登陆失败,如果用了当天的参数,在第一次提交的时候,TRY里面的提交肯定会报405的错误,但是except中的提交是成功的,如果提交按钮再按一次,try里的提交就成功了,不报任何错误。不解啊~~~~
odbc1230 2011-09-15
  • 打赏
  • 举报
回复
弄错了,和IdHTTP1.ProtocolVersion :=pv1_1;IdHTTP1.HTTPOptions:=[hoKeepOrigProtocol];没关系,其中22906fbbd9903dab9e77f627c808b724=aa5334c99185df63172bd0f7489c1757这组参数每天会变化,用了今天的参数就会报405错误,如果是昨天的参数就不会报错。
Mit1208 2011-09-15
  • 打赏
  • 举报
回复
郁闷,22906fbbd9903dab9e77f627c808b724=aa5334c99185df63172bd0f7489c1757如果这两句会每天变化的话,你可以打开http://passport.19lou.com/login/index/t/normal这个页面截取然后再将参数赋值啊!
还有你的OnRedirect这个事件要加上登陆时的COOKIE的,不加的话,还是未登陆状态,请问你加了吗?
遇到问题自己思考一下噢。。。
odbc1230 2011-09-15
  • 打赏
  • 举报
回复
IdHTTP1.ProtocolVersion :=pv1_1;
IdHTTP1.HTTPOptions:=[hoKeepOrigProtocol];
加了你这两句,就可以去掉405的错误了,但是现在收到的没显示啊,用了Utf8ToAnsi();也不行,OnRedirect事件没有触发。
odbc1230 2011-09-14
  • 打赏
  • 举报
回复
用httpwatch抓的包,核对了下,只能说以我的理解是对的,呵呵,不知道问题在那里,请高手分析了。
bdmh 2011-09-14
  • 打赏
  • 举报
回复
确认你的参数都对吗,用抓包软件看看提交的都是哪些内容,跟你的对一对
山东蓝鸟贵薪 2011-09-14
  • 打赏
  • 举报
回复
顶顶帖子,看看先
接分中........

1,594

社区成员

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

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