Installed RadSudio 10.1 Berlin.
First encountered with Indy. I can not understand what is wrong.
Does not want to work out the code.

All on an event on one button hung up for check of work with components.

You get an error in both versions:

Project Project1.exe raised exception class EIdUnknownProtocol with message 'Unknown Protocol'

IdTCPClient1.Connect; - passes without errors.

Get gives an error to any site. What's wrong?

The first variation without special settings:

procedure TForm1.Button1Click(Sender: TObject); var IdTCPClient1 : TIdTCPClient; IdHTTP1 : TIdHTTP; IdCookieManager1 : TIdCookieManager; begin IdTCPClient1 := TIdTCPClient.Create(nil); IdHTTP1 := TIdHTTP.Create(IdTCPClient1); IdCookieManager1 := TIdCookieManager.Create(IdTCPClient1); //---- //Настраиваем компонент. IdHTTP1.HandleRedirects := True; IdHTTP1.AllowCookies := True; IdTCPClient1.Port := 80; IdTCPClient1.Host := 'mail.ru'; //---- try IdTCPClient1.Connect; Memo1.Text := IdHTTP1.Get(IdTCPClient1.Host); finally IdTCPClient1.Disconnect; IdCookieManager1.Free; IdHTTP1.Free; IdTCPClient1.Free; end; end; 

The second option - the same error crashes:

 procedure TForm1.Button1Click(Sender: TObject); var IdTCPClient1 : TIdTCPClient; IdHTTP1 : TIdHTTP; IdCookieManager1 : TIdCookieManager; begin IdTCPClient1 := TIdTCPClient.Create(nil); IdHTTP1 := TIdHTTP.Create(IdTCPClient1); IdCookieManager1 := TIdCookieManager.Create(IdTCPClient1); //---- //Настраиваем компонент. IdHTTP1.HandleRedirects := True; IdHTTP1.AllowCookies := True; IdHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22'; IdHTTP1.Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; IdHTTP1.Request.AcceptLanguage := 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4'; IdHTTP1.Request.AcceptCharSet := 'windows-1251,utf-8;q=0.7,*;q=0.3'; IdTCPClient1.Port := 80; IdTCPClient1.Host := 'mail.ru'; //---- try IdTCPClient1.Connect; Memo1.Text := IdHTTP1.Get(IdTCPClient1.Host); finally IdTCPClient1.Disconnect; IdCookieManager1.Free; IdHTTP1.Free; IdTCPClient1.Free; end; end; 

When I put ' http://mail.ru ' - then already on IdTCPClient1.Connect; the error takes off:

Project Project1.exe raised exception class EIdSocketError with message 'Socket Error # 11001 Host not found.

  • It is necessary to use exactly Indy components. - Programmer

1 answer 1

If you try to access http://mail.ru/ in the browser, you will be redirected to https://mail.ru/ (get the HTTP / 1.1 302 server response).

Since you specified Indy to follow the redirects automatically in Indy, he, having received the answer 302, will make a new request and will try to access the https version of the site. BUT to establish a secure connection, in Indy you must specify a secure connection handler, since by default, Indy can only handle unprotected http connections. This is done approximately like this:

 uses IdHTTP, IdSSLOpenSSL, IdCookieManager; procedure IndyTest; var VResp: string; VIdHTTP: TIdHTTP; VIdCookieManager: TIdCookieManager; VIdIOHandler: TIdSSLIOHandlerSocketOpenSSL; begin VIdHTTP := TIdHTTP.Create(nil); try VIdCookieManager := TIdCookieManager.Create(nil); VIdIOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil); try VIdHTTP.IOHandler := VIdIOHandler; VIdHTTP.CookieManager := VIdCookieManager; VIdHTTP.HandleRedirects := True; VIdHTTP.AllowCookies := True; VResp := VIdHTTP.Get('http://mail.ru/'); finally VIdCookieManager.Free; VIdIOHandler.Free; end; finally VIdHTTP.Free; end; end; 

At the same time, you must have OpenSSL installed, or there must be 2 libraries next to exe : libeay32.dll and ssleay32.dll .

  • Thank! It helped and earned with SSL! - Programmer
  • @Programmer then mark the answer as a solution. - zed
  • An example of a great answer. - Interface Unknown