使用Indy连接到Gmail

Oue*_*ine 2 delphi gmail indy10

我正在尝试使用Delphi XE5通过Indy组件登录Gmail(而不是电子邮件),使用此功能:

procedure TForm1.Button1Click(Sender: TObject);
var
  http : TIdHTTP;
  S, GALX, Email, Pass : String;
  lParam : TStringList;

begin
  try
    lParam := TStringList.Create;
    try
      http := TIdHTTP.Create(nil);
      http.IOHandler := IOHandler;
      http.CookieManager := Cookie;
      http.AllowCookies := true;
      http.HandleRedirects := true;
      http.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0';
      http.Request.Host := 'accounts.google.com';
      http.Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
      http.Request.ContentType := 'application/x-www-form-urlencoded';

      S := http.Get('https://accounts.google.com/ServiceLogin');

      Delete(S, 1, Pos('GALX', S));
      S := Copy(S, 1, Pos('">', S) - 1);
      Delete(S, 1, Pos('value=', S) + length('value='));

      GALX := S;

      lParam.Add('GALX='+GALX);
      lParam.Add('Email='+Email);
      lParam.Add('Passwd='+Pass);

      Memo1.Lines.Add(http.Post('http://accounts.google.com/ServiceLoginAuth', lParam));
    finally
      http.Free;
    end;
  finally
    lParam.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

现在每当我尝试执行我得到的时候:HTTP/1.0.405 Method Not Allowed. 我只在电子邮件/传递正确时才会收到此错误,当电子邮件/传递错误时,我会得到通常的错误页面,所以我猜这不是POST方法不是允许.

我在这做错了什么?

Rem*_*eau 6

您没有提交所有要/ServiceLoginAuth查找的输入字段.如果您查看HTML /ServiceLogin,/ServiceLoginAuth除了您已发送的3之外,还有8个其他字段已发布.从HTML表单提交数据时,您必须提交HTML表单要提交的所有内容,您不能只选择您想要的内容.尝试添加其他字段,看看会发生什么.

您需要在发布时/ServiceLoginTIdHTTP.Request.Referer属性中提供URL,/ServiceLoginAuth以便它认为请求来自/ServiceLogin.

您正在/ServiceLogin使用HTTPS 进行检索,但您正在/ServiceLoginAuth使用HTTP 进行发布.您需要使用HTTPS.

当用户有多个Google帐户,/ServiceLogin帖子到/AccountChooser,然后重定向回到/ServiceLogin其他输入参数,因此您可能还需要考虑到这一点.

发布到/ServiceLoginAuth重定向到/CheckCookie,然后重定向到/ManageAccount,因此请确保这些请求在每个步骤都是完整和准确的.