- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了一个使用 libcurl 的多线程程序,但有时 curl 会提示它在 exec curl_easy_perform 后无法解析主机名,有时则不会。
size_t Http::WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
MemoryStruct *mem = (MemoryStruct *)userp;
mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
assert(NULL != mem->memory);
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
void Http::run(const URL &url, Http::FinishedCallback cbk)
{
CURL *handle = curl_easy_init();
if (handle)
{
MemoryStruct *chunk = new MemoryStruct;
chunk->memory = (char *)malloc(1); /* will be grown as needed by the realloc above */
chunk->size = 0; /* no data at this point */
CURLcode res;
curl_easy_setopt(handle, CURLOPT_URL, url.getUrl().c_str());
curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)chunk);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(handle, CURLOPT_TIMEOUT, 10L);
curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 10L);
res = curl_easy_perform(handle);
/* check for errors */
if (CURLE_OK != res)
{
chunk->status = false;
std::string errCode = std::to_string(res);
chunk->memory = (char *)realloc(chunk->memory, chunk->size + errCode.size() + 1);
memcpy(&(chunk->memory[chunk->size]), errCode.c_str(), errCode.size());
chunk->size += errCode.size();
chunk->memory[chunk->size] = 0;
}
else
{
chunk->status = true;
}
#ifdef _DEBUG
chunk->url = url;
#endif
cbk(chunk);
free(chunk);
curl_easy_cleanup(handle);
}
}
void Http::get(URL url, FinishedCallback cbk)
{
std::thread http(&Http::run, Http(), url, cbk);
http.detach();
}
Http::~Http()
{
curl_global_cleanup();
}
int index = 0;
bool finish = false;
void func(Http::MemoryStruct *memo)
{
if (!memo->status)
{
#ifdef _DEBUG
LOG(INFO) << "Failure:\t" << curl_easy_strerror((CURLcode)atoi(memo->memory)) << "\n";
#endif
}
else
{
//LOG(INFO) << memo->memory << '\n';
}
finish = memo->status;
++index;
}
int main(void)
{
curl_global_init(CURL_GLOBAL_ALL);
URL::AttribMap attribMap{ { "class", "System" }, { "token", "KY0SQ3FX996PU1ZO" }, { "type", "GetConfig" } };
URL url("open.55.la", "/index.php", attribMap);
Http http;
while(index++ <=10)
{
try
{
http.get(url, func);
}
catch (std::_System_error &err)
{
LOG(INFO) << err.what();
}
}
while (true)
{
;
}
el::Loggers::flushAll();
return EXIT_SUCCESS;
}
最佳答案
这是 libcurl 为 CURLE_COULDNT_RESOLVE_HOST
返回的错误消息错误代码 (6)。
我会引用 Exit status section from the curl book
Couldn't resolve host. The given remote host's address was not resolved. The address of the given server could not be resolved. Either the given host name is just wrong, or the DNS server is misbehaving and doesn't know about this name when it should or perhaps even the system you run curl on is misconfigured so that it doesn't find/use the correct DNS server.
关于curl - 为什么 libcurl 有时会提示 'Couldn' t resolve host name'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43450899/
这里的 IT 网络/编程学生试图完成一项作业,但我遇到了障碍。我们的任务是读取文本文件,将单词放入 ArrayList 中,并对内容执行字符串操作。我能够将单词拉入 ArrayList、按升序对内容进
编辑:我收到以下错误代码: Error adding accessory The operation couldn’t be completed. (HMErrorDomain error 2.) 和
您好,我正在尝试测试套接字激活机制,但无法连接到服务器。 curl --unix-socket/run/gunicorn.sock本地主机 curl: (7) Couldn't connect to
所以我安装了sandbox (运行 centOS)来自 hortonworks在 virtualBox带网络配置>>> bridged network我编辑了bashrc导出http_proxy和 h
我目前正在开发一个android应用程序,提交一个post请求并处理相应的响应。 我能够将发布请求发送到相应的 URL,但是当我尝试检索响应时,我得到了一半的 HTML 内容,然后是“*无法从 STD
我在将 ServiceLoader 集成到我的 Android 应用程序以集成插件系统时遇到问题。 public class StrategieClassLoader extends URLClass
我有一个类似于以下的自定义数据类型: data Token = Number Int | Otherthings 我希望能够以一种方式使用“数字”,以另一种方式使用其他东西。所以
当我尝试从 Visual Studio Code 运行一个简单的 React Native 应用程序时,我收到以下错误消息。 Scanning folders for symlinks in C:\P
我最近从Java搬到了Kotlin。将整个项目转换为Kotlin,将pom.xml转换为build.gradle。我正在使用Kotlin,Gradle,Cucumber Sernity,Appium构
我在执行docker-compose命令时遇到Powershell中的错误: 尽管从Docker Quickstart Terminal运行相同的命令可以正常工作: 最佳答案 确保首先在Powersh
当我运行docker build时,我得到了: Sending build context to Docker daemon 10.24kB WARN[11935] Couldn't run aup
我在运行 SDL 程序时遇到此错误。它编译得很好,但是窗口打开了一小会儿然后就关闭了。 这是我的代码: //Using SDL and standard IO #include #include
我正在编写一个基于 Google map 的 Android 应用程序。应用程序本身运行良好,没有任何问题。我可以看到 map ,缩放到我的当前位置等等。根据 AndroidManifest.xml,
我在实际设备上仅在生产和开发容器上都遇到了这个错误。模拟器能够很好地获取记录。这发生在通过 XCode 运行的开发构建、TestFlight 构建和 AppStore 上的实时生产构建上。 所有设备
我正在创建一个模板化的快速排序函数,它应该允许我使用迭代器对一个定制的双向链表类进行快速排序。我遇到了错误 In file included from main.cpp:21.0: quicksort
我有一个模板类和一个具有模板返回类型的函数: template class Wrapper { public: Wrapper(const T& _data) : data(_data) {
将 Jersey 从 1.15 版升级到 1.17 版后,它开始记录以下消息: Apr 2, 2013 5:13:06 PM com.sun.jersey.server.wadl.generators
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我有一个 android 应用程序在我将设备更新到 android 4.4 (kitkat) 之前一直运行没有问题。 现在我开始收到这个错误,并且程序的某些部分在日志 cat_ 中被破坏了_ Andr
我通过 git clone 成功安装了 Directus CMS。在数据库中创建了 15 个表。在/config 文件夹中,我的 projectkey.php 文件也已创建。安装后我想使用我的凭据登录
我是一名优秀的程序员,十分优秀!