Login to website with Synapse lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- P.curtis · 2020-05-26 07:56 Hi All, I'm trying to use HTTPSend to login to a website with something like :- Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   HTTPSender := THTTPSend.Create;  HTTPSender.MimeType := 'application/x-www-form-urlencoded';  HTTPSender.UserName:='jorblogs';  HTTPSender.Password:='notforyou';  HTTPGetResult := HTTPSender.HTTPMethod('POST', 'https:\\www.somesite.com');  but it doesnt work. I get a resonse, but not logged in. What am I missing? Thanks in advance. ---------------------------------------------------------------------- egsuh · 2020-05-26 08:07 There may be several possibilities. 1. The action target may not be www.somesite.com. It can be www.somesite.com/login, or any other script defined.  You'll have to check the action property of the browser form. 2. Your method will not succeed if www.somesite.com are checking other data than username and password, like cookies or hidden field data. 3.  BTW, how do you check whether you are logged in via Synapse? ---------------------------------------------------------------------- rvk · 2020-05-26 08:11 Quote from: P.curtis on May 26, 2020, 09:56:09 ambut it doesnt work. I get a resonse, but not logged in. What am I missing? And what response so you get? Also, you're using https, so did you put the openssl libraries in your exe directory? ---------------------------------------------------------------------- P.curtis · 2020-05-26 08:20 SSL stuff is OK. I get a HTML  page as a response. Looking through the HTML code I can see that I am not logged in. The site is based on vBulletin. ---------------------------------------------------------------------- rvk · 2020-05-26 09:26 Quote from: P.curtis on May 26, 2020, 10:20:33 amThe site is based on vBulletin. Then you can't login with the Username and Password properties of THTTPSend. Those are for website where you can pass username and password via the socket. Like https://myuser:password@mydomain.com You need to look at the way the login is implemented. For example, you can look in Chrome, with F12 developer tools, what is actually posted during a login. If the login is relatively simple, like just passing username and password in a form, then it's simple. If it has a more sophisticated login, like Google and Facebook, then login in will be much harder. If I look at a vBulletin site it does do a post with username=aaaaaaa& password=bbbbbbbb&privacyconsent=1&securitytoken=guest form-data to /auth/ajax-login, but I'm not sure if that's the only data it sends. ---------------------------------------------------------------------- P.curtis · 2020-05-26 11:26 @rvk. Thanks. Any idea or code on how to handle what you wrote QuoteIf I look at a vBulletin site it does do a post with username=aaa aaaa&password=bbbbbbbb&privacyconsent=1&securitytoken=guest form-data to /auth/ajax-login, but I'm not sure if that's the only data it sends. ---------------------------------------------------------------------- rvk · 2020-05-26 12:27 Quote from: P.curtis on May 26, 2020, 01:26:53 pmAny idea or code on how to handle what you wrote Something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses httpsend, synautil; procedure TForm1.Button1Click(Sender: TObject);var  HTTPSend: THTTPSend;  Ok: boolean;  ForumUrl, Username, Password: string;  TextFromDocument: string;begin   ForumUrl := 'https://forum.vbulletin.com';  Username := 'someuser';  Password := 'somepassword';   HTTPSend := THTTPSend.Create;  try    HTTPSend.MimeType := 'application/x-www-form-urlencoded';    WriteStrToStream(HTTPSend.Document,      ansistring('username=' + Username + '&password=' + Password +      '&privacyconsent=1&securitytoken=guest'));    Ok := HTTPSend.HTTPMethod('POST', ForumUrl + '/auth/ajax-login');    TextFromDocument := ReadStrFromStream(HTTPSend.Document, HTTPSend.Document.Size);    Memo1.Lines.Add('---------------');    Memo1.Lines.Add('Result = ' + HTTPSend.ResultCode.ToString + ' ' + HTTPSend.ResultString);    Memo1.Lines.Add('---------------');    Memo1.Lines.Add(HTTPSend.Headers.Text);    Memo1.Lines.Add('---------------');    Memo1.Lines.Add(TextFromDocument);    Memo1.Lines.Add('---------------');  finally    HTTPSend.Free;  end;end; You'll need to see what you get back and if you need to set cookies and session-variables. You could use the cookie-mechanism of Synapse and save them from HTTPSend (of use the same HTTPSend for following requests).