想通过idhttp.get(URL) 获得页面的html信息.但希望是在登陆状态下获取信息.
笨想加载IE已登陆的cookie来实现已登陆效果.
但测试过后还是获取的未登陆页面内容.
请教下如何用post来登陆.
截取登陆时的信息如下.
POST /user/logon.asp?url= 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, application/x-silverlight, */*
Referer: http://www.xici.net/
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; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
Host: user.xici.net
Content-Length: 103
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: __utma=242994182.1898981310.1206595330.1211850459.1211856743.102; __utmz=242994182.1211788451.100.18.utmccn=(organic)|utmcsr=baidu|utmctr=%CC%EC%D6%AE%B3%E8%B6%F9+%CE%F7%EC%F4|utmcmd=organic; vjuid=723a439f8.118eeaf9ed6.0.813315b25e433; vjlast=1211856824; __utmc=242994182; __utmb=242994182; CityId=142320100; HostID=93f010541930fcdf-3f19d37353c88bf5275726dcf620bd84; __utma=207079066.1634525919.1206594044.1211853686.1211856549.148; __utmz=207079066.1211853686.147.12.utmccn=(referral)|utmcsr=user.xici.net|utmcct=/|utmcmd=referral; desktop=1; SessionID=FC4D7679710A6CCC; ServerID=1055; uid=0; __utmc=207079066; xicifrmact=1; __utmb=207079066; cs_FC4D7679710A6CCC=1
logPath=&UserName=用户名&Password=密码&Logon=%B5%C7%C2%BC&UserCode=FB39C84B465E30CEDD090A98FF41B235西祠的地址是 http://www.xici.net 请赐教.

解决方案 »

  1.   

    你试试看post
    http://user.xici.net/user/logon.asp?id="张三"pw="12345"看看
      

  2.   

    试了一下,但不成功
    POST /user/user/user/logon.asp?url= HTTP/1.1
    Connection: Keep-Alive
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 101
    Cache-control: no-cache
    Cookie: __utma=242994182.1898981310.1206595330.1211850459.1211856743.102; __utmz=242994182.1211788451.100.18.utmccn=(organic) |utmcsr=baidu |utmctr=%CC%EC%D6%AE%B3%E8%B6%F9+%CE%F7%EC%F4 
    |utmcmd=organic; vjuid=723a439f8.118eeaf9ed6.0.813315b25e433; vjlast=1211856824; __utmc=242994182; __utmb=242994182; CityId=142320100; HostID=93f010541930fcdf-3f19d37353c88bf5275726dcf620bd84; 
    __utma=207079066.1634525919.1206594044.1211853686.1211856549.148;  __utmz=207079066.1211853686.147.12.utmccn=(referral) |utmcsr=user.xici.net |utmcct=/ 
    |utmcsr=user.xici.net |utmcct=/ |utmcmd=referral; desktop=1; SessionID=FC4D7679710A6CCC; ServerID=1055; uid=0; __utmc=207079066; xicifrmact=1; __utmb=207079066; cs_FC4D7679710A6CCC=1
    Host: search.114.vnet.cn
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, */*
    Accept-Encoding: gzip, deflate
    Accept-Language: zh-cn
    Referer: http://www.xici.net/
    User-Agent:  Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; .NET CLR 1.1.4322; .NET CLR 2.0.50727)logPath=&UserName=我的密码c&Password=lhz123&Logon=%B5%C7%C2%BC&UserCode=FB39C84B465E30CEDD090A98FF41B235 返回:HTTP/1.1.400.Bad.Request..Date:.Wed,.28.May.2008.07:52:09.GMT..Server:.Apache..Content-Length:.485..Connection:.close..Content-Type:.text/html;.charset=iso-8859-1....<!DOCTYPE.HTML.PUBLIC."-//IETF//DTD.HTML.2.0//EN">.<html><head>.<title>400.Bad.Request</title>.</head><body>.<h1>Bad.Request</h1>.<p>Your.browser.sent.a.request.that.this.server.could.not.understand.<br./>.Request.header.field.is.missing.':'.separator.<br./>.<pre>.|utmcmd=organic;.vjuid=723a439f8.118eeaf9ed6.0.813315b25e433;.vjlast=1211856824;.__utmc=242994182;.__utmb=242994182;.CityId=142320100;.HostID=93f010541930fcdf-3f19d37353c88bf5275726dcf620bd84;.</pre>.</p>.</body></html>.
      

  3.   

    再顶一下.谢谢LS的.我用TWebBrowser实现了自动登陆的功能.但就是资源消耗过大.请求高人继续给予帮助.
      

  4.   

    放个IdCookieManager1,先用idhttp去get,在IdCookieManager1的onnewcookie事件里记录下acookie.ClientCookie;post的时候idHttp1.Request.CustomHeaders.Text:=cookies;最好用vsniffer之类的嗅探器看下cookie的格式,我以前做的一个自动登陆程序,IdCookieManager1取到的cookie字串和实际需要的不太一样,需要自己手动修改下
      

  5.   


    function getcook():boolean;
    var
       str2,cookies:string;
    begin
    result:=false;
    if CanGetIECookie(hosturl,str2) then
       iecookie:=copy(str2,pos('warlord2',str2),length(str2)-pos('warlord2',str2)+1)
    else
       exit;cookies:='Cookie: '+iecookie+'; '+idcookiestr;
    idHttp1.Request.CustomHeaders.Text:=cookies;
    idHttp1.CookieManager.CookieCollection.Clear;
    result:=true;
    end;procedure TForm1.IdCookieManager1NewCookie(ASender: TObject;
      ACookie: TIdCookieRFC2109; var VAccept: Boolean);
    begin
    idcookiestr:=acookie.ClientCookie;
    end;function TForm1.CanGetIECookie(const URL:string;var Cookie:string):boolean;
    var
       lpvBuffer:array[0..1000] of byte;
       lpdwBufferLength:cardinal;
    begin
    lpdwBufferLength:=sizeof(lpvBuffer);
    result:=InternetGetCookie(PChar(URL),nil,@lpvBuffer,lpdwBufferLength);
    if result then
       Cookie:=pchar(@lpvBuffer);
    end;这些大致是以前我一个程序的代码.其实我也不太懂cookie.不过用嗅探器发现,实际访问的cookie是ie的cookie和idhttp的get得到的cookie组合而成的.然后就这么试了下,结果就可以了. 希望对楼主有所启发.另外,以前我那个网站还会检查idhttp的Request.Referer,如果不符合也无法登陆