我需要一个程序,轮询网站每秒和响应,如果网站没有在15秒内回应。我从一个示例程序中编写了以下代码。在试运行时,它在15秒内打印了7次。我不能让curl_easy_perform在响应前等待15秒吗?
int main(void)
{
CURL *curl;
CURLcode res;
char *postthis="moo mooo moo moo";
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.101");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postthis);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postthis));
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15);
while(1)
{
Sleep(1000);
res = curl_easy_perform(curl);
if(res!= CURLE_OK)
printf("nada \n");
}发布于 2011-02-28 02:13:24
Sleep(15000 - timeTakenForCurlInMs);发布于 2011-02-28 02:28:49
这是一个愚蠢的黑客攻击,每秒都会失败。它是基于POST教程。我破解了GET的东西,它工作得很好。
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://URL_HERE");
**curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);**
while(1)
{
Sleep(1000);
res = curl_easy_perform(curl);
if(res== CURLE_OK) printf("\n\n yeah \n");
else printf("\n\n nada \n");
}
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}https://stackoverflow.com/questions/5133968
复制相似问题