WinHTTP Cannot resolve the host name first time

135 views Asked by At

I have a Delphi application that uses WinHTTP. Everything was fine until two weeks back. However, some users started to experience the "Server Name cannot be resolved" error when the application tried to access a remote server for the first time. But it resolves after that. They might get it the next day as well.

I have about 100 users experiencing this. But I have many more users who have no problem. Also, a few users had the error persistently. The drivers/etc/hosts file entry solved the problem for them. What could be the reason?

Here is the basic code:

      httpRequest := CoWinHTTPRequest.Create;
      httpRequest.SetTimeouts(60000,60000,60000,60000);   //1 minute for everything
      httpRequest.Open('POST',url,False);


      jsPostRequest.AddPair('email',UserName);
      jsPostRequest.AddPair('password',Password);
      jsPostRequest.AddPair('ttl','8');
      RequestStr := jsPostRequest.ToString;


      httpRequest.SetRequestHeader('Content-type','application/json');

      try

        httpRequest.send(RequestStr);

      except on e:Exception do

         ShowMessage(e.message);   //<------------ ERROR       
      end;

Update:

I don't have this problem if I use Indy TIdHTTP.

What makes Indy can resolve the DNS but WinHTTP cannot?

0

There are 0 answers