gpt4 book ai didi

c++ - 未为 cURL 启用 IDN 支持

转载 作者:行者123 更新时间:2023-11-28 06:08:07 26 4
gpt4 key购买 nike

我在使用 cURL 将图像放入动态内存缓冲区时遇到了一些问题。

使用的代码如下:

struct memoryStruct {
char *memory;
size_t size;
};

static void* CURL_realloc(void *ptr, size_t size)
{
/* There might be a realloc() out there that doesn't like reallocing
NULL pointers, so we take care of it here */
if(ptr)
return realloc(ptr, size);
else
return malloc(size);
}

size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
struct memoryStruct *mem = (struct memoryStruct *)data;

mem->memory = (char *)CURL_realloc(mem->memory, mem->size + realsize + 1);

if (mem->memory)
{
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
}

return realsize;
}




int main()
{
std::string everything = "https://upload.wikimedia.org/wikipedia/commons/1/1e/Stonehenge.jpg";
CURL *curl; // CURL objects
CURLcode res;
memoryStruct buffer; // memory buffer

curl = curl_easy_init(); // init CURL library object/structure

if(curl) {

// set up the write to memory buffer
// (buffer starts off empty)

buffer.memory = NULL;
buffer.size = 0;

// (N.B. check this URL still works in browser in case image has moved)

curl_easy_setopt(curl, CURLOPT_URL, everything);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); // tell us what is happening

// tell libcurl where to write the image (to a dynamic memory buffer)

curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl,CURLOPT_WRITEDATA, (void *) &buffer);

// get the image from the specified URL

res = curl_easy_perform(curl);


curl_easy_cleanup(curl);
free(buffer.memory);

}
return 0;
}

作为错误输出,我收到如下错误信息: enter image description here

但是我不确定是否理解所显示的错误。我的猜测是我应该为 curl 启用 IDN 支持吗?但是我不确定如何进行。这是否意味着我必须在启用 IDN 的情况下重新编译库? (如果我找到了怎么做)

谢谢你的帮助

最佳答案

您正在将一个 std::string 对象传递给 curl_easy_setopt,而您应该传递一个 C 字符串。它实际上是在尝试解决天知道的问题。

curl_easy_setopt(curl, CURLOPT_URL, everything.c_str());

关于c++ - 未为 cURL 启用 IDN 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31951879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com