登录twitch.tv

时间:2015-07-19 09:33:14

标签: delphi http indy

我正在尝试登录此网站,花了一些时间在此但没有成功(下载http://www.twitch.tv/settings看起来没有记录用户)。

我正在使用Delphi XE 8(Update 1)和最新的SSL文件。当前代码如下(真实用户和密码):

var
  IdHTTP: TIdHTTP;
  IdSSL: TIdSSLIOHandlerSocketOpenSSL;
  HTML: string;
  para: TStringList;
  start, ends: integer;
  stream: TMemoryStream;
  state, nonce: string;
begin
    IdHTTP := TIdHTTP.Create;
    para := TStringList.Create;
    stream := TMemoryStream.Create;
    try
      IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP);
      IdHTTP.IOHandler := IdSSL;
      IdHTTP.AllowCookies := True;
      IdHTTP.CookieManager := Form1.IdCookieManager1;
      Form1.IdCookieManager1.CookieCollection.Clear;
      IdHTTP.HandleRedirects := True;
      HTML := IdHTTP.Get('http://www.twitch.tv/login');
      start := Pos('<input type="hidden" name="state" value="', HTML) + Length('<input type="hidden" name="state" value="');
      ends := PosEx('"', HTML, start);
      state := copy(HTML, start, ends - start);
      start := Pos('<input type="hidden" name="nonce" value="', HTML) + Length('<input type="hidden" name="nonce" value="');
      ends := PosEx('"', HTML, start);
      nonce := copy(HTML, start, ends - start);
      para.Add('scope=openid');
      para.Add('client_id=36926892495301a63b2e9350a38d3d6dbf72ad81e571a3ebba4687250ec8f352c70b3e91229602f73e1335528f3caa00a5cf513f484d7003784e722f2ce7a216');
      para.Add('redirect_uri=https://secure.twitch.tv/passport/callback');
      para.Add('response_type=code');
      para.Add('state=' + state);
      para.Add('nonce=' + nonce);
      para.Add('login=1a64');
      para.Add('password=1a641a641a64');
      try
        IdHTTP.Post(' https://passport.twitch.tv/authorize', para, stream, IndyTextEncoding_UTF8());
      except
      end;
      try
        Form1.Memo1.text := para.text;
        HTML := IdHTTP.Get('http://www.twitch.tv/settings');
      except
      end;
      showmessage(HTML);
    finally
      IdHTTP.Free;
      para.Free;
      stream.Free;
    end;
end;

1 个答案:

答案 0 :(得分:0)

问题在于空间 IdHTTP.Post(' https://passport.twitch.tv/authorize', para, stream, IndyTextEncoding_UTF8());

应为IdHTTP.Post('https://passport.twitch.tv/authorize', para, stream, IndyTextEncoding_UTF8());

一切都好吗