Recent

Author Topic: [SOLVED] Indy and Proxy  (Read 2262 times)

DanishMale

  • Jr. Member
  • **
  • Posts: 73
[SOLVED] Indy and Proxy
« on: January 20, 2019, 05:27:43 pm »
I am trying to create an app where IdHTTP can login on a remote machine (no HTTPS needed)

I have written this code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.IdHTTPProxyAuthorization(Sender: TObject;
  2.   Authentication: TIdAuthentication; var Handled: Boolean);
  3. begin
  4.   Handled := True;
  5. end;
  6.  
  7. procedure TForm1.IdHTTPStatus(ASender: TObject; const AStatus: TIdStatus;
  8.   const AStatusText: string);
  9. begin
  10.   Memo1.Lines.Add('Status: '+ AStatusText);
  11. end;
  12.  
  13.  
  14. procedure TForm1.Button1Click(Sender: TObject);
  15. Var
  16.   IdHTTP : TIdHTTP;
  17.   Resp : string;
  18. begin
  19.   IdHTTP := TIdHTTP.Create;
  20.   try
  21.     try
  22.       with IdHTTP do
  23.       begin
  24.         OnStatus := @IdHTTPStatus;
  25.         OnProxyAuthorization := @IdHTTPProxyAuthorization;
  26.  
  27.         HTTPOptions := [hoInProcessAuth];
  28.         ProtocolVersion := pv1_0;
  29.         ProxyParams.BasicAuthentication := False;
  30.         ProxyParams.ProxyServer := '999.999.99.999';
  31.         ProxyParams.ProxyPort := 8080;
  32.         ProxyParams.ProxyUsername := 'USER';
  33.         ProxyParams.ProxyPassword := 'USER';
  34.  
  35.         //HandleRedirects probably only necessary in this demo
  36.         HandleRedirects := True;
  37.       end;
  38.       // Connect to Open ATV (Linux) unit
  39.       Resp := IdHTTP.Get('http://999.999.99.999:9999/?logpoll.html?lastid=0');
  40.       Memo1.Lines.Add('Response: '+ Resp);
  41.     except
  42.       on e : Exception do
  43.       begin
  44.         Memo1.Lines.Add('Error:' + e.Message);
  45.       end;
  46.     end;
  47.   finally
  48.     Freeandnil(IdHTTP);
  49.   end;
  50. end;
  51.  

This is the results I am getting:

Code: Pascal  [Select][+][-]
  1. Status: Connecting to 999.999.99.999.
  2. Status: Connected.
  3. Status: Disconnected.
  4. Error:HTTP/1.0 401 Unauthorized
  5.  

Just confused on what I am missing/doing wrong ..................

Any help appreciated in advance


Found another solution with HTTPsend
« Last Edit: January 25, 2019, 01:41:56 am by DanishMale »
Lazarus 2.2.4 x64 | Windows 10 x64 | Windows Server 2019 x64 | OpenVix 5.4 (Linux) | MySQL Community Server 8.0 x64 | MariaDB 10.5.8 x64 | SQLite 3.40.0 x64 | PostgresSQL 13.1 x64

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Indy and Proxy
« Reply #2 on: January 20, 2019, 08:35:33 pm »
with that many digits in the IP 999, which is more than 255 of course, wouldn't the ProtocolVersion not
be VP1_0 but like VP6_0  or something ?

Something I just noticed
The only true wisdom is knowing you know nothing

DanishMale

  • Jr. Member
  • **
  • Posts: 73
Re: Indy and Proxy
« Reply #3 on: January 20, 2019, 08:43:38 pm »
@ jamie : It's just  anonymized IPv4 address with 9s  :D 
Lazarus 2.2.4 x64 | Windows 10 x64 | Windows Server 2019 x64 | OpenVix 5.4 (Linux) | MySQL Community Server 8.0 x64 | MariaDB 10.5.8 x64 | SQLite 3.40.0 x64 | PostgresSQL 13.1 x64

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Indy and Proxy
« Reply #4 on: January 20, 2019, 09:16:53 pm »
Please look at this line you have in your code

ProtocolVersion := pv1_0;
                           ^^^^^

Shouldn't we be at pv4_0 or something ?

Don't pay any attention to me, I was born in Maine, USA, where everyone is related.


 
The only true wisdom is knowing you know nothing

DanishMale

  • Jr. Member
  • **
  • Posts: 73
Re: Indy and Proxy
« Reply #5 on: January 20, 2019, 09:53:39 pm »
@ jamie .. nope it's protocol of the IdHTTP component which is HTTP protocols either 1.0 (pv1_0) or 1.1 (pv1_1)
Lazarus 2.2.4 x64 | Windows 10 x64 | Windows Server 2019 x64 | OpenVix 5.4 (Linux) | MySQL Community Server 8.0 x64 | MariaDB 10.5.8 x64 | SQLite 3.40.0 x64 | PostgresSQL 13.1 x64

 

TinyPortal © 2005-2018