I have a function (with Host = 'https://api.ipify.org/'):
TRespEx=record
Resp:IHttpResponse;
EError:String
end;
function CheckIp(UseProxy: Boolean = True; Host: String = ipcheck;
ProxyHost: String = '127.0.0.1'; ProxyPort: Integer = 9090): TRespEx;
var
Cli: THttpClient;
begin
Cli := THTTPClient.Create;
Cli.SecureProtocols := [THTTPSecureProtocol.SSL2, THTTPSecureProtocol.SSL3,
THTTPSecureProtocol.TLS1, THTTPSecureProtocol.TLS11,
THTTPSecureProtocol.TLS12, THTTPSecureProtocol.TLS13];
try
try
if UseProxy = True then Cli.ProxySettings.Create(ProxyHost, ProxyPort);
Cli.SetUserAgent(PUserAgent);
Result.Resp := Cli.Get(Host);
except
on E: Exception do
Result.EError := E.Message;
end;
finally
Cli.Free;
end;
end;
It worked well wthout proxy(False), but a few days ago it broke down. The exception (E.Message) returns an error:
Error sending data: (12002) The operation time out
I do nothing, I did not change any code. And the function still works, but only with proxy params(True). I know, you say that I blocked the Host, but it still works fine in a browser.
PUserAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0'. I just copied it from my browser user agent.
I turned off the antivirus and firewall, but the result is the same.
Any ideas? I don't understand what the problem is.
If you call the function as you say, then you are using a proxy, which in this case is installed on the local machine (127.0.0.1) and TCP port 9090.
Are you sure that the proxy is still up and running?
If don't want to use this proxy, then you have to call the function with
'False'as the first parameter.A more simplified code, could be the following:
Also, you are saying that when you are using the proxy server, the connection is establishing successfully. But when you are not using the proxy, you are getting the error.
Something like this, is possible if the PC you are working on, has connection issues (eg: firewall, routing table, bad dns configuration etc). In this case, the direct connections from the PC doesn't work, but the connections made through proxy works.