我用HttpAnalyzer截到的cookie和我自己程序cookie不一样,差了十万八千里,貌似是indy没解析对,登陆后,通过这个函数得到的cookie和HttpAnalyzer看到的一样,但是转到另一个页面,就不对了。function GetCookie(var AIdHTTP:TIdHTTP): string; var k:integer; FCookie:TIdCookieManager; begin Result := ''; FCookie := AIdHTTP.CookieManager; for k:= 0 to FCookie.CookieCollection.Count -1 do begin Result := Result + FCookie.CookieCollection.Items[k].CookieText; end; end;
用的是idhttp1.response.rawheaders.text;
然后自己截取!INDY9要使用上边的方法!
不过你的是INDY10不用获取COOKIE,直接在GET或POST后直接操作就行了,COOKIE自动附带进去了
var
k:integer;
FCookie:TIdCookieManager;
begin
Result := '';
FCookie := AIdHTTP.CookieManager;
for k:= 0 to FCookie.CookieCollection.Count -1 do
begin
Result := Result + FCookie.CookieCollection.Items[k].CookieText;
end;
end;
同样等答案
差十万八千里...我一直使用IDHTTP弄COOKIE什么的,没遇到过不能弄的呀
虽然有时候和自己使用抓包软件截取的不一样.但是重要的那个SessionID截取到就行!
使用再idhttp.request.customheaders.text:='cookie:' + sessionid;
这样就行了.往后再跳到子页面都不会有错误的!不知道你是如何弄的.如可以发邮件我看下
[email protected]
var
postList: TStrings;
begin
EditURL.Text := 'http://passport.csdn.net/account/loginbox?callback=logined';
with IdHTTP do
begin
Request.Accept := 'text/html, */*';
Request.ContentLength := 0;
Request.ContentRangeEnd := 0;
Request.ContentRangeStart := 0;
Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
Request.ContentType := 'application/x-www-form-urlencoded';
HandleRedirects := true; AllowCookies :=true;
end; postList := TStringList.Create;
try
postList.Add('u=xxx');
postList.Add('p=xxxx');
postList.Add('chkRemember=1'); IdHTTP.Post(EditURL.Text, postList); ShowMessage(IntToStr(IdCookieManager1.CookieCollection.Count )); finally
EditURL.Text := IdHTTP.Response.Server + ': ' + IdHTTP.Response.ResponseText;
postList.Free;
end;怎么我测试的登录 csdn 的 无论用户名密码 给什么值 都返回
nginx/0.7.68: HTTP/1.1 200 OK明显没有登录成功吗 而且 IdCookieManager1 总是 0