[SOLVED] LAMW - jhttpclient login with cookie and ssl lazarus / 43-Android ---------------------------------------------------------------------- Segator · 2020-08-28 16:13 Hi people, i have an functional python example code, to login an internal network, but i not found the pascal way using the jhttpclient, this is the python example: 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 def conection_very_data(username, password):    """    :param username: Número de teléfono registrado en la plataforma de mi.cubacel.net    :param password: Contraseña registrada en la plataforma de mi.cubacel.net    :return: Interpretación de BeautifulSoup del código fuente de la pagina de datos del perfil    """    urllib3.disable_warnings()    r2 = requests.get("https://mi.cubacel.net:8443/login/images/cimg/86.jpg", verify=False,                      cookies=requests.session().cookies, stream=True)    data = {        "language": "es_ES",        "username": username,        "password": password,        uword": "every"    }    r3 = requests.post("https://mi.cubacel.net:8443/login/Login", data=data, verify=False, cookies=r2.cookies)    r5 = requests.get("https://mi.cubacel.net/primary/_-ijqJlSHh", verify=False, cookies=r3.cookies)    soup = BeautifulSoup(r5.text, "html.parser")    return soup and this is my try implementation: 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 var  cookie:jobject;begin  cookie:=jHttpClient1.AddCookie('https://mi.cubac el.net:8443/login/images/cimg/86.jpg','verify','false');  jHttpClient1 .GetAsync('https://mi.cubacel.net:8443/login/images/cimg/86.jpg');  jhttpclient1.SetCookieAttributeValue(cookie,'language','es_ES');  jhttpclient1.SetCookieAttributeValue(cookie,'username','user1');  jhttpclient1.SetCookieAttributeValue(cookie,'password','xxxx');  jhttpclient1.SetCookieAttributeValue(cookie,'uword','every');    jhttpclient1.AddNameValueData('language','es_ES');  jhttpclient1.AddNameValueData('username','user1');  jhttpclient1.AddNameValueData('password','xxxx');  jhttpclient1.AddNameValueData('uword','every');   jhttpclient1.PostNam eValueDataAsync('https://mi.cubacel.net:8443/login/Login','language=es _ES&username=user1&password=xxxx&uword=every');  //ShowMessage(contentsum);  jhttpclient1.GetAsync('https://mi.cubacel. net/primary/_-ijqJlSHh');end; the page not respond, any help? ---------------------------------------------------------------------- jmpessoa · 2020-08-28 17:47 Quotehe page not respond, any help? "jHttpClient1.GetAsync" and "jhttpclient1.PostNameValueDataAsync"  are Asynchronous! So, you need to handle the corresponding events.... ---------------------------------------------------------------------- Segator · 2020-08-28 18:15 Hi jmpessoa, Quote"jHttpClient1.GetAsync" and "jhttpclient1.PostNameValueDataAsync"  are Asynchronous! So, you need to handle the corresponding events.... yes i manage that, the problem is 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 r2 = requests.get("https://mi.cubacel.net:8443/login/images/cimg/86.jpg", verify=False,                      cookies=requests.session().cookies, stream=True)    data = {        "language": "es_ES",        "username": username,        "password": password,        uword": "every"    }    r3 = requests.post("https://mi.cubacel.net:8443/login/Login", data=data, verify=False, cookies=r2.cookies)    r5 = requests.get("https://mi.cubacel.net/primary/_-ijqJlSHh", verify=False, cookies=r3.cookies) r2 is a request to a captcha imagen  that save the cookies in some where to make a post request (r3) with that cookie, context and data. r5 is a get with the r3 cookies as parameter and with the loggin done. the cuestion es how i do this with jhttpclient? my try responce with "" content ---------------------------------------------------------------------- jmpessoa · 2020-08-28 18:50 But Quoter2 = requests.get(................ Is synchronous  logic..... so, change the LAMW code to  synchronous  methods, too. Or refactore your code for Asynchronous logic....  [not sequential line after line ....] ---------------------------------------------------------------------- Segator · 2020-08-28 19:13 yes you are right, when you call getasync the above code have not effect over that method because it has move to other threads i think, i am go to make some changes and find a public webpage to logging with jhttpclient using coockies for you can do tests ---------------------------------------------------------------------- Segator · 2020-08-29 13:52 I make some progress, this code work: 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 jWebView1.Navigate('https://mi.cubacel.net/primary/_-ijqJlSHh');  jHttpClient1.ClearCookieStore();   cookie:=jHttpClient1.AddCookie('htt ps://mi.cubacel.net:8443/login/images/cimg/86.jpg','verify','false');  jHttpClient1.GetStateFul('https://mi.cubacel.net:8443/login/images/ci mg/86.jpg');   jHttpClient1.AddNameValueData('language', 'es_ES');  jHttpClient1.AddNameValueData('username', 'xxxx');  jHttpClient1.AddNameValueData('password', 'xxxx');  jHttpClient1.AddNameValueData('uword', 'every');  ShowMessage(jHttpCli ent1.PostStateful('https://mi.cubacel.net:8443/login/Login'));   jetda taformat.text:=jhttpclient1.Get('https://mi.cubacel.net/primary/_- ijqJlSHh');  / but this is a synchrony code and the app is freezing some time, i try to use jAsyncTask component but the app crash (i removed the toast and the interface interaction of course), the other problem is an strange thing, if i not open the page firt with a webview the jhttpclient response with '' string, is a ssl problem maybe i add openssl to the uses clause, but one problem at a time 😀, so any asynchronous solution like this? ---------------------------------------------------------------------- jmpessoa · 2020-08-29 18:23 try change the last line to: jetdataformat.text:=jhttpclient1.GetAsync('https://mi.cubacel.net/prim ary/_-ijqJlSHh'); and handle the result in the event.... ---------------------------------------------------------------------- Segator · 2020-08-30 01:01 Yes that solution work 👍, now the other rare problem, jhttpclient not open an https sites, but if you open that sites first with a webview then jhttpclient can downloaded the html, i add the openssl to the uses but i can't use jhttpclient without webview to browse https sites?, any suggestions or solution?. ---------------------------------------------------------------------- jmpessoa · 2020-08-30 01:24 Indeed, jhttpclient don't  have [yet] a good support to https .... sorry. ---------------------------------------------------------------------- Segator · 2020-08-30 14:31 but we can try to improved it, i see other thread with https or ssl problem and  the people copy a openssl arm build to the folder library, but the system (android) have the own ssl library, must by a way to use it with out using an external it's the ssl library the problem?. ---------------------------------------------------------------------- jmpessoa · 2020-08-30 16:42 Quotethe people copy a openssl arm build to the folder library... Yes, a pure Free Pascal  using "FPHttpClient.pas"  solution.... Quote but the system (android) have the own ssl library.... this is what we need! ---------------------------------------------------------------------- Segator · 2021-01-16 21:39 Finally i solve the jhttpclient ssl problem with untrusted certificates, i add a new function to trust all certificates, use this if you really trust in the URL for security reasons, just wait the @jmpessoa approval in the github code and update it. ---------------------------------------------------------------------- jmpessoa · 2021-01-17 13:55 Done! Thank you! [Help] What about "put" and "delete"?   [so we can support RestFull Apis....] You can try mimic  the "get" [or "post"]  method code... ---------------------------------------------------------------------- Segator · 2021-01-17 14:26 I make some search an maybe is simple as change the method name like client3.setRequestMethod("GET") to client3.setRequestMethod("PUT") or DELETE, maybe is look like better a function to change this with the same mimic as "setRequestMethod" in jhttpclient.