这是我截获的数据:
POST /login/zh/?ref=https://www.battlenet.com.cn/account/management/&app=bam&cr=true HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, */*
Referer: https://www.battlenet.com.cn/login/zh/?ref=https://www.battlenet.com.cn/account/management/&app=bam&cr=truehttps://www.battlenet.com.cn/login/zh/?ref=https://www.battlenet.com.cn/account/management/&app=bam&cr=true
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: www.battlenet.com.cn
Content-Length: 64
Connection: Keep-Alive
Cache-Control: [email protected]&password=haitaoma1980&persistLogin=on

我就是照着这个原样,在delphi7里写的,但什么反应也没有,返回都是空字符串,快愁死我了。。下面是代码:
procedure TForm1.Button4Click(Sender: TObject);
var
  Param:TStringList;
  RStream:TMemoryStream;
  mystr:TStringList;
  FLogStr:string;
begin
  IdHTTP2.Request.CustomHeaders.Clear;
  IdHTTP2.Request.Accept := 'image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, */*' ;
  IdHTTP2.Request.Referer := 'https://www.battlenet.com.cn/login/zh/?ref=https://www.battlenet.com.cn/account/management/&app=bam&cr=true';
  IdHTTP2.Request.AcceptLanguage := 'zh-cn';
  IdHTTP2.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727)';
  IdHTTP2.Request.ContentType := 'application/x-www-form-urlencoded';
  IdHTTP2.Request.AcceptEncoding := 'gzip, deflate';
  IdHTTP2.Request.Host := 'www.battlenet.com.cn';
  IdHTTP2.Request.ContentLength := 64;
  IdHTTP2.Request.Connection := 'Keep-Alive';
  IdHTTP2.Request.CacheControl := 'no-cache';
  Param:=TStringList.Create;
  RStream:=TMemoryStream.Create;
  Param.Add('[email protected]');
  Param.Add('password=haitaoma1980');
  Param.Add('persistLogin=on');
  IdHTTP2.HTTPOptions:= IdHTTP2.HTTPOptions + [hoKeepOrigProtocol];
  IdHTTP2.HTTPOptions := IdHTTP2.HTTPOptions - [hoForceEncodeParams]; //去掉自动编码
  IdHTTP2.HandleRedirects := True;//允许自动跳转   IdHTTP2.Post('https://www.battlenet.com.cn/login/zh/?ref=https://www.battlenet.com.cn/account/management/&app=bam&cr=true', Param,RStream);
   mystr :=  TStringList.Create;
   mystr.LoadFromStream(RStream);
   Memo1.Text := mystr.Text ;
  RStream.Free;
  end;返回值一直是空,界面还有IdCookieManager1,IdSSLIOHandlerSocket1两个空间都与IDHTTP2相关联了,
大家给想个办法吧,有空的话,帮小弟我测试一下,都一个星期了,还是搞不定,郁闷delphiIDHTTPPOSTHTTPS

解决方案 »

  1.   

    当我直接用下面代码时,网站是有回应的:
    Param.Text := '[email protected]&password=haitaoma1980&persistLogin=on';提示账号密码错误,但一旦用上面的代码,也就是账号密码正确的时候,服务器就不反悔任何的信息,真是什么情况啊,大家帮帮忙吧
      

  2.   

    IdHTTP2.Request.AcceptEncoding := 'identity';
      

  3.   

    加上这句试试:
    IDHTTP2.ProtocolVersion := pv1_1;
      

  4.   

    这个问题终于解决了,原因有两个:
    0:IdHTTP2.Request.AcceptEncoding := 'identity'; 或是IdHTTP2.Request.AcceptEncoding := ''; 自解压模式。
    1:我用的事delphi7 ,是delphi7本省的组件,或是类库(dll)问题(很无语,以后不用delphi7了,用XE)
      

  5.   

    但现在有有一个新问题了,现在能登录成功,但是登录成功后,我要获取里面的一些链接,然后再次使用Get方法获取子页面的信息,第一个IDHTTP的Cookie可以传给第二个IDHTTP,但里面有个小问题就是链接再get时候,会给原来保存到的Cookie添加了一个这个东东:
     __utma=160654882.1915462864.1364961628.1364961628.1365305164.2; __utmb=160654882.1.10.1365305164; __utmz=160654882.1364961628.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=160654882
    网上查了查:是Google的免费网站统计系统产生的信息,
    哎,又不知所措了,该如何下手呢?