#include <iostream>
#include <curl/curl.h>
#include <locale>
#include <codecvt>
using namespace std;
// 回调函数,用于处理接收到的响应数据
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* response)
{
size_t totalSize = size * nmemb;
response->append((char*)contents, totalSize);
return totalSize;
}
int main() {
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::locale::global(std::locale("")); // 设置全局的本地化环境
std::wcout.imbue(std::locale()); // 设置宽字符输出流的本地化环境
CURL* curl = curl_easy_init();
if (curl) {
std::string url = "https://m.51ping.com/live/centercontrol/component/decorate/obsscenes?liveid=10086&appid=1&yodaReady=h5&csecplatform=4&csecversion=2.1.2";
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// 设置接收响应数据的回调函数
std::string response;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L); //设置连接超时为10秒:
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L); //总体操作超时 整个传输过程的超时时间
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) {
std::cerr << "Failed to send HTTP request: " << curl_easy_strerror(res) << std::endl;
}
else
{
std::wstring wstr = converter.from_bytes(response);
std::wcout << "Response: " << wstr << std::endl;
}
curl_easy_cleanup(curl);
}
cout << "come on";
cout << endl;
cout << "I say \"Thank you\" ";
return 0;
}