title: CURL Request Failure retry method
body: <p>I am using CURL library for POST, GET, download and upload data. For some reason if request fails then we planned to retry the request again. we planned to retry for 5 times, even then fails then we stop and display failure message to user. For this we are running this in loop with delay of 10 second. </p>
  
  <p>My question.</p>
  
  <p>1) Is my approach to this is correct. </p>
  
  <p>2) what is the best practice.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
      CURL *curl;
      CURLcode res;
  
      int nRetryCount = 0;
      do 
      {
          curl_global_init(CURL_GLOBAL_DEFAULT); 
  
          curl = curl_easy_init();
          if(curl) 
          {
              curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");
  
              res = curl_easy_perform(curl);
  
              curl_easy_cleanup(curl);
  
              if(CURLE_OK == res) 
              {
                  break;
              }
  
              nRetryCount++;
  
              if (nRetryCount &lt; 5)
              {
                  //wait for 10 sec.
                  Sleep(10000);
              }       
          }
      } while (nRetryCount &lt; 5);
  
  
      curl_global_cleanup();
  
      return 0;
  }
  </code></pre>