[fpc-pascal] Ethernet Relays

Michael Van Canneyt michael at freepascal.org
Tue Sep 8 20:29:52 CEST 2020



On Tue, 8 Sep 2020, James Richters via fpc-pascal wrote:

> Yes 10 was too short,  I made it larger and larger until it worked.  1000 was the lowest value that worked so I set it to 2000, that's still quite a bit faster than the default.
>
> If I make a mistake in the link but the server IP address is correct, I get a valid connection but then it fails and terminates with:
> An unhandled exception occurred at $0000000100017675:
> EHTTPClient: Unexpected response status code: 401
>
> If I use the wrong IP address, but that IP address has a different server running on it, but that page is not available, I get:
> An unhandled exception occurred at $0000000100017675:
> EHTTPClient: Unexpected response status code: 401
>
> Is there a way to obtain these errors as well so it doesn't terminate my program?

Yes, catch the EHTTPClient exception just as you catch the ESocketError:

    try
      S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/30000/15');
    except
      On E: ESocketError do
       Writeln('Could not connect to server: ',E.Message);
      On EH : EHTTPClient do
       begin
       Writeln('Error getting the document : '+EH.Message);
       end;
    end;

If you created a TFPHTTPClient instance you can also examine the
ResponseStatusCode property, it will contain the server response code.


Michael.


More information about the fpc-pascal mailing list