Recent

Author Topic: TFPHTTPClient with proxy and HTTPS protocol  (Read 10394 times)

Abelisto

  • Jr. Member
  • **
  • Posts: 91
TFPHTTPClient with proxy and HTTPS protocol
« on: August 03, 2018, 05:26:24 am »
Is the subj possible? If yes - how?

There is the simple test program:

Code: Pascal  [Select][+][-]
  1. program proxy;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.     Classes, SysUtils, openssl, fphttpclient;
  7.  
  8. procedure SetProxy(AHttp: TFPHTTPClient; const AUrl: string);
  9. var
  10.     i: Integer;
  11. begin
  12.     with AHttp.Proxy do
  13.     begin
  14.         if AUrl <> '' then
  15.         begin
  16.             i := Pos(':', AUrl);
  17.             Host := Copy(AUrl, 1, i - 1);
  18.             Port := StrToInt(Copy(AUrl, i + 1, Length(AUrl)));
  19.             UserName := '';
  20.             Password := '';
  21.             Writeln(ErrOutput, Format('Set proxy Host: %s, Port: %d', [Host, Port]));
  22.         end
  23.         else
  24.         begin
  25.             Host := '';
  26.             Port := 0;
  27.             UserName := '';
  28.             Password := '';
  29.         end;
  30.     end;
  31. end;
  32.  
  33. var
  34.     url, proxy: string;
  35.     http: TFPHTTPClient;
  36.     responce: string;
  37. begin
  38.     if ParamCount > 1 then
  39.     begin
  40.         proxy := ParamStr(1);
  41.         url := ParamStr(2);
  42.     end
  43.     else
  44.     begin
  45.         proxy := '';
  46.         url := ParamStr(1)
  47.     end;
  48.     http := TFPHttpClient.Create(nil);
  49.     http.IOTimeout := 5000;
  50.     SetProxy(http, proxy);
  51.     responce := http.Get(url);
  52.     Writeln(responce);
  53.     http.Free;
  54. end.
  55.  

Next calls works just fine:

./proxy 185.93.3.123:8080 http://www.lazarus-ide.org
./proxy https://www.lazarus-ide.org
curl --proxy 185.93.3.123:8080 https://www.lazarus-ide.org


But

./proxy 185.93.3.123:8080 https://www.lazarus-ide.org

gives

ESocketError: Connect to 185.93.3.123:8080 failed.
« Last Edit: August 03, 2018, 07:34:23 am by Abelisto »
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: TFPHTTPClient with proxy and HTTPS protocol
« Reply #1 on: August 03, 2018, 12:29:38 pm »
Well. Use trunk for that. There have been quite a few changes including a related one with an example in the last few weeks.
Specialize a type, not a var.

Abelisto

  • Jr. Member
  • **
  • Posts: 91
Re: TFPHTTPClient with proxy and HTTPS protocol
« Reply #2 on: August 03, 2018, 02:12:41 pm »
@Thaddy Thanks, but it seems that the result is same, even with packages/fcl-web/examples/httpclient/httpget.pas example.
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

 

TinyPortal © 2005-2018