I am trying to log in to Craigslist using Delphi 2010 and latest version of Indy 10, and retrieve my account page (in order to gather a listing of all my posts).
However, when I post the login details, the returned HTML is that of the login page, whereas I expect to get my account page listing my postings.
Here is my latest code:
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;
I have confirmed through debugging that the email and password are correct values as they are passed in the request parameters, so why don't I get the page I expect?
According to the HTML you receive, the name of the login field is inputEmailHandle
, not login
. Likewise, the password field is inputPassword
, not password
. There are also some additional fields that you omit, including step
, rt
, and rp
. I see no op
or redirect
fields in the form.
In other words, the code shown here is not code for logging in to Craigslist; it's code for logging in to Filestrum with the addresses changed around, without regard for the significance of the surrounding code.