当我尝试登录Craigslist时,为什么会出现登录页面?

时间:2013-03-26 13:58:25

标签: delphi indy craigslist

我正在尝试使用Delphi 2010和最新版本的Indy 10登录Craigslist,并检索我的帐户页面(为了收集我所有帖子的列表)。

但是,当我发布登录详细信息时,the returned HTMLthat of the login page,而我希望得到my account page listing my postings

这是我最新的代码:

function TfrmMain.Login: string;
var
  IdHTTP: TIdHTTP;
  Request: TStringList;
  Response: TMemoryStream;
  SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
  Result := '';
  try
    Response := TMemoryStream.Create;
    try
      Request := TStringList.Create;
      try
        Request.Add('op=login');
        Request.Add('redirect=http://www.craigslist.org/');
        Request.Add('login=' + edtEmail.Text);
        Request.Add('password=' + edtPassword.Text);
        IdHTTP := TIdHTTP.Create;
        try
          SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
          try
            SSLHandler.SSLOptions.Method := sslvSSLv3;
            SSLHandler.SSLOptions.Mode := sslmUnassigned;

            IdHTTP.IOHandler := SSLHandler;
            IdHTTP.AllowCookies := True;
            IdHTTP.HandleRedirects := True;
            IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
            IdHTTP.Post('https://accounts.craigslist.org/login', Request, Response);
            Result := IdHTTP.Get('https://accounts.craigslist.org/');
          finally
            SSLHandler.Free;
          end;
        finally
          IdHTTP.Free;
        end;
      finally
        Request.Free;
      end;
    finally
      Response.Free;
    end;
  except
    on E: Exception do
      ShowMessage(E.Message);
  end;
end;

我已经通过调试确认电子邮件和密码是正确的值,因为它们在请求参数中传递,所以为什么我不能得到我期望的页面?

1 个答案:

答案 0 :(得分:4)

根据您收到的HTML,登录字段的名称为inputEmailHandle,而不是login。同样,密码字段为inputPassword,而不是password。您还省略了一些其他字段,包括steprtrp。我看到表单中没有opredirect字段。

换句话说,此处显示的代码不是登录Craigslist的代码;地址发生了变化code for logging in to Filestrum,而不考虑周围代码的重要性。

相关问题