Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > C/C++ Сетевое программирование
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый Сегодня, 06:37   #1
test2me
Новичок
Джуниор
 
Регистрация: 21.07.2025
Сообщений: 5
По умолчанию curl desktop send request to website. объясните простыми словами..

Код:
#include <iostream>
#include <string>
#include <curl/curl.h>
#include <iostream>
using namespace std;


static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main(void)
{
  CURL *curl;
  CURLcode res;
  std::string readBuffer;

  curl = curl_easy_init();
  if(curl) {
    // url
    curl_easy_setopt(curl, CURLOPT_URL, "https://yandex.ru");
    // https
    curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_3);
    //create text from url
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    //send string readbuffer as link to the callback function
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    //send request
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);

    std::cout << readBuffer << std::endl;
  }
  return 0;
}
Объясните простыми словами, что делают эти функции?
Код:
  //create text from url
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    //send string readbuffer as link to the callback function
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
test2me вне форума Ответить с цитированием
Старый Сегодня, 09:57   #2
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,833
По умолчанию

curl_easy_setopt
Цитата:
curl_easy_setopt is used to tell libcurl how to behave. By setting the appropriate options, the application can change libcurl's behavior. All options are set with an option followed by a parameter.
CURLOPT_WRITEFUNCTION
Цитата:
Callback for writing data. See CURLOPT_WRITEFUNCTION
Цитата:
Pass a pointer to your callback function, which should match the prototype shown above.

This callback function gets called by libcurl as soon as there is data received that needs to be saved. For most transfers, this callback gets called many times and each invoke delivers another chunk of data. ptr points to the delivered data, and the size of that data is nmemb; size is always 1.

The data passed to this function is not null-terminated.
CURLOPT_WRITEDATA
Цитата:
Data pointer to pass to the write callback. See CURLOPT_WRITEDATA
Цитата:
A data pointer to pass to the write callback. If you use the CURLOPT_WRITEFUNCTION option, this is the pointer you get in that callback's fourth and last argument. If you do not use a write callback, you must make pointer a 'FILE ' (cast to 'void ') as libcurl passes this to fwrite(3) when writing data.
p51x вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Curl, proxy, insta. Объясните принцип работы Aleskandr Помощь студентам 1 16.01.2018 09:12
Curl error: with the SSL CA cert (php + curl + ssl) Hell Knight PHP 1 27.12.2014 14:30
Что такое интерфейс программы? Простыми словами) TwiX Общие вопросы Delphi 6 11.11.2010 03:01
объясните своими словами Anett// Помощь студентам 1 05.06.2010 07:18
Объясните новичку, что такое массив, если можно своими словами. Maxximuss Помощь студентам 5 26.10.2008 09:26