Forum > PDAs and Smartphones

[SOLVED] LAMW. jHttpClient doesn't work with https protocol



I'm trying to reach an url with the https:// prefix using jHttpClient, but with not success so far (it works ok with http://)

I've read on almost all related topic in this forum, and I've put different android and inside /libs/armeabi-v7a folder. I've tried with synapse, ...

In this link,46830.15.html the user MrBean uploaded a working example (, but sadly it's not there anymore.

Please. How can I reach that kind of urls?

Thanks in advance

After a lot of tries, It seems that the problem is that Synapse doesn't seem to work, I mean, it compiles ok, but then, even for not https, urls, it gets always empty strings. I've read in,49443.msg360431.html#msg360431 that there ws a problem with older versions of fpc.exe, but I'm using fpc 3.2.0.

For instance, here are several tests:

  SynHttp := THTTPSend.Create;
  SynHttp.HTTPMethod('GET', 'http://...'); //+'?id='+id+'&mensaje='+mensaje);
  respuesta := TStringList.create;
  incluyeEnLista('Synapse GET: '+respuesta.Text);


  response := TMemoryStream.create;
     incluyeEnLista('Synapse POST: '+StreamToString(response));


  respuesta := tStringList.create;
  incluyeEnLista('Synapse 2 '+respuesta.Text);     

The same url, using jHttpClient, works (but not with a https url):

  HttpClient.AddNameValueData('id', id);
  HttpClient.AddNameValueData('mensaje', mensaje);
  //Non-blocking! handled by:  OnCodeResult and OnContentResult

I've recompiled laz_synapse and it seems to localize openssl libraries:
Ventana de Mensajes
Verbose: Selected chip architecture: armeabi-v7a
Verbose: Taking libraries from folder: ...\libs\armeabi-v7a
Verbose: Found library:
Verbose: Found library:
Verbose: Found library:
Compilar paquete laz_synapse 40.1: Éxito

Please, Could someone of you give me some example or a hint to keep trying?

Hi new around here and idk if this helps but this is something I was playing with to make an https request to get some JSON,

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit suppliesMeUnit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, fphttpclient, opensslsockets; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Edit1: TEdit;    Label1: TLabel;    Memo1: TMemo;    procedure dpSurprise(Sender: TObject);    procedure Label1Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.dpSurprise(Sender: TObject);var  Client : TFPHttpClient;  S : String;   begin  Client := TFPHttpClient.Create(nil);  Client.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');  Client.AddHeader('Content-type','application/json; charset=UTF-8');  Client.AddHeader('Accept', 'application/json');  Client.AllowRedirect := true;  S := Client.Get(Edit1.Text);  Memo1.Caption := S; end; procedure TForm1.Label1Click(Sender: TObject);begin end; end.  

Thanks for trying to help, ralphtheprog, but I don't think that's the solution.

Indeed, yout approach works on Windows or Linux (I have used fphttpclient unit regularly without problems in those two systems with http and with https). However, in Android it doesn't seem to work. Look my example:

procedure TAndroidModule1.Button1Click(Sender: TObject);
  r,a : string;
     ListView1.Add('TFPCustomHTTPClient.SimpleFormPost|Request: '+r+'|Response: '+a);
     on e : exception do begin
       ListView1.Add('TFPCustomHTTPClient.SimpleFormPost|Request: '+r+'|Response: '+e.Message);

Even with a valid http URL, it gets:

Response: Host name resolution for "..." failed.

I've tried with LNet too:

procedure TAndroidModule1.Button2Click(Sender: TObject);
  HttpClient: TLHTTPClient;
  r, Host, URI, FileName, AltFileName: ansistring;
  Port: Word;
  UseSSL: Boolean;
  SSLSession: TLSSLSession;
     dummy := THTTPHandler.Create;
     dummy.form := Self;
     UseSSL := DecomposeURL(r, Host, URI, Port);
     HttpClient := TLHTTPClient.Create(nil);
     SSLSession := TLSSLSession.Create(HttpClient);
     SSLSession.SSLActive := UseSSL;
     HttpClient.Session := SSLSession;
     HttpClient.Host := Host;
     HttpClient.Method := hmGet;
     HttpClient.Port := Port;
     HttpClient.URI := URI;
     HttpClient.Timeout := -1;
     HttpClient.OnDisconnect := @dummy.ClientDisconnect;
     HttpClient.OnDoneInput := @dummy.ClientDoneInput;
     HttpClient.OnError := @dummy.ClientError;
     HttpClient.OnInput := @dummy.ClientInput;
     HttpClient.OnProcessHeaders := @dummy.ClientProcessHeaders;
     on e : exception do begin
       ListView1.Add('TLHTTPClient|Request: '+r+'|Answer: '+e.Message);
       writeln('TLHTTPClient|Request: '+r+'|Answer: '+e.Message);

It's interesting that, when running the LNet example without putting and in \libs\armeabi-v7a, the code raises the exception Unable to initialize OpenSSL Library, please check your OpenSSL installation. That suggests (as the formerly commented Host name resolution for "..." failed) that the problem is not the openssl libs, but the access to Internet from pascal specific code.

In fact, so far, I've only been able to get a http (not https) response using jHTTPClient.

Here ( I read that, for https accessing, the AndroidManifest.xml has to have android:usesCleartextTraffic="true" informed inside the Application tag, but I've checked and that line is already there, so I'm running out of ideas.

Without accessing to https urls it's almost impossible to build a modern day regular communication app, that's why I'm investing so much time in this problem. Please, help me!

Thanks in advance.

Hi again.

I've been able to solve the problem.

First of all, the jHttpClient object WORKS RIGHT WITH HTTPS! :-[ The problem was a weird interaction between my company's firewall and a ssl certificated wrong configured. I'm really sorry.

Secondly, I haven't been able to make any of the pure pascal based NET components that I've tried (TFPHttp, LNET and Synapse) to work in Android. For all of you with time and desire to follow with the effort, I've developed a test program which you can access to here:!AphGvmscOT8qgZh8364yUjNsZoJobQ?e=n4YGw3

As stated in prior messages, when you try:

jHttpClient button -> Almost inmediate Right answer gor http and https requests
TFPHttp button -> after some seconds blocking the app (around 10): Host name resolution for "ave.b...." failed
Synapse -> After around 30 seconds blocking the app: Empty response ('')
LNet -> After around 10 seconds blocking the app -> no response at all

Thanks for your help!


[0] Message Index

Go to full version