2

I use Indy 10.6.2 with Delphi 7.

I must connect to a https server. I use this code :

FIdHTTP := TIdHTTP.Create(nil);
FIdHTTP.HandleRedirects := True;
FIdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
FIdSSL.SSLOptions.Mode := sslmClient;
FIdSSL.SSLOptions.SSLVersions := [sslvTLSv1_1,sslvTLSv1_2];
FIdHTTP.IOHandler := FIdSSL;

FIdHTTP.Request.Clear;
FIdHTTP.Request.ContentType := 'application/json';
FIdHTTP.Response.ContentType := 'application/json';
FIdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Basic xxxxxxx==';
FIdHTTP.Post(zURL, zJsonStreamIn, zJsonStreamOut);
finally
  zJSon := zJsonStreamOut.DataString;
end;

we have a proxy on lan : http://proxy-client.xxxxx.fr Port : 8080

I use proxyparams :

FIdHTTP.ProxyParams.ProxyServer := 'http://proxy-client.in.ac-grenoble.fr';
FIdHTTP.ProxyParams.ProxyPort := 8080;
FIdHTTP.ProxyParams.BasicAuthentication := False;

Then I have error 10001 (host not found) but when I dont't use proxyparams, I have 10060.

Do you have any idea please ?

Thank you in advance.

1 Answer 1

3

The TIdHTTP.ProxyParams.ProxyServer property expects just a hostname, not a full URL. Change this line:

FIdHTTP.ProxyParams.ProxyServer := 'http://proxy-client.in.ac-grenoble.fr';

To this instead:

FIdHTTP.ProxyParams.ProxyServer := 'proxy-client.in.ac-grenoble.fr';

On a side note:

You don't need the following lines, so you should remove them completely:

FIdHTTP.Request.Clear;
FIdHTTP.Response.ContentType := 'application/json';
FIdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Basic xxxxxxx=='; 

TIdHTTP has builtin support for Basic authentication. Simply set the TIdHTTP.Request.Username and TIdHTTP.Request.Password properties as needed, and set the TIdHTTP.Request.BasicAuthorization property to True.

Also, if you want the response data as a string, TIdHTTP.Post() has an overload for that purpose:

zJson := IdHTTP.Post(zURL, zJsonStreamIn);

But either way, putting the call to TIdHTTP.Post() in a try..finally is good for cleanup, but if an HTTP error occurs, your zJson won't receive any data by default. If you need the response body for HTTP errors, you will need to either:

  • catch the resulting EIdHTTPProtocolException and assign its ErrorMessage property to your zJson variable.

  • enable the hoNoProtocolErrorException and hoWantProtocolErrorContent flags in the TIdHTTP.HTTPOptions property, then zJson will receive both success and failure response bodies equally.

1
  • Hi Remy, thanks' a lot for your help. I'll try this immediately.
    – varlau
    Mar 1, 2022 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.