Untitled
unknown
plain_text
3 years ago
1.9 kB
8
Indexable
#include <iostream>
#include <curl/curl.h>
#include <string>
// İstek yanıtını işlemek için callback fonksiyonu
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* output) {
size_t totalSize = size * nmemb;
output->append(static_cast<char*>(contents), totalSize);
return totalSize;
}
int main() {
CURL* curl;
CURLcode res;
std::string previousContent;
std::string currentContent;
// İzlenecek web sitesinin URL'sini belirleyin
std::string url = "http://www.example.com";
// CURL kütüphanesini başlatın
curl_global_init(CURL_GLOBAL_DEFAULT);
// CURL handle'ı oluşturun
curl = curl_easy_init();
if (curl) {
// İstek yapılacak URL'yi belirtin
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// İstek yanıtını işlemek için callback fonksiyonunu ayarlayın
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, ¤tContent);
// İstek gönderin
res = curl_easy_perform(curl);
// İstek başarılıysa
if (res == CURLE_OK) {
// Önceki içerik ile mevcut içeriği karşılaştırın
if (previousContent != currentContent) {
std::cout << "Web sitesinde değişiklik tespit edildi!" << std::endl;
}
else {
std::cout << "Web sitesinde değişiklik yok." << std::endl;
}
// Mevcut içeriği önceki içeriğe kopyalayın
previousContent = currentContent;
}
else {
std::cerr << "İstek gönderilirken bir hata oluştu: " << curl_easy_strerror(res) << std::endl;
}
// CURL handle'ını temizleyin
curl_easy_cleanup(curl);
}
// CURL kütüphanesini kapatın
curl_global_cleanup();
return 0;
}
Editor is loading...