Search code examples
delphihttpdelphi-2010indy

Login to craigslist to retrieve account page using Delphi and Indy and SSL


I am trying to log into craigslist using Delphi, and retrieve my account page (in order to gather a listing of all my posts)

However, I can't seem to get the login to work, what Am I doing wrong?

function TfrmMain.Login: string;
var
  IdHTTP: TIdHTTP;
  Request: TStringList;
  Response: TMemoryStream;
begin
  Result := '';
  try
    Response := TMemoryStream.Create;
    try
      Request := TStringList.Create;
      try
        Request.Add('op=login');
        Request.Add('redirect=http://newyork.craigslist.org/');
        Request.Add('login=' + myEmail);
        Request.Add('password=' + myPassword);
        IdHTTP := TIdHTTP.Create;
        try
          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
          IdHTTP.Free;
        end;
      finally
        Request.Free;
      end;
    finally
      Response.Free;
    end;
  except
    on E: Exception do
      ShowMessage(E.Message);
  end;
end;

I get a exception class EIdIOHandlerPropInvalid with message 'IOHandler value is not valid' on the line:

IdHTTP.Post('https://accounts.craigslist.org/login', Request, Response);

thanks


Solution

  • See (Indy) TIdHTTP EIdSocketError Socket Error # 0 exceptions when downloading files and the suggestions in the comments. It looks like you should upgrade to a more recent version of Indy.