卷曲很慢(我假设我没有正确设置选项)
Curl is slow (I assume I am not setting an option correctly)
我写了这个最小的例子来展示我的问题:
#include "curl/curl.h"
#include <stdexcept>
#include <string>
#include <iostream>
#include <stdlib.h>
int main(int argc,char* argv[])
{
// All error checking removed for clarity.
// But all calls return CURLE_OK
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1");
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
curl_easy_perform(curl);
long result;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &result);
std::cout << "HTTP RESPONCE: " << result << "n";
}
编译并运行:
> g++ test.cpp -lcurl
> ./a.out thorsanvil.com
<html><head><title>Nothing here</title></head><body><h1>Nothing Here</h1><h2>Go away</h2></body></html>
HTTP RESPONCE: 200
real 0m5.144s
user 0m0.016s
sys 0m0.000s
如您所见,从服务器获得响应需要 5 秒.
如果我使用 wget 重复相同的命令,则只需 0.2 -> 0.5 秒
> time wget thorsanvil.com
--2012-05-28 05:24:17-- http://thorsanvil.com/
Resolving thorsanvil.com (thorsanvil.com)... 67.170.22.105
Connecting to thorsanvil.com (thorsanvil.com)|67.170.22.105|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104 [text/html]
Saving to: `index.html'
100%[======================================================================================================================>] 104 --.-K/s in 0s
2012-05-28 05:24:18 (589 KB/s) - `index.html.3' saved [104/104]
real 0m0.493s
user 0m0.008s
sys 0m0.000s
但是使用 curl 命令行工具也很慢
> time curl thorsanvil.com
<html><head><title>Nothing here</title></head><body><h1>Nothing Here</h1><h2>Go away</h2></body></html>
real 0m5.240s
user 0m0.004s
sys 0m0.012s
关于为什么我的简单版本没有按预期工作的任何想法?
编辑
从评论。libcurl 的版本
> ls -la /usr/lib/x86_64-linux-gnu/libcurl*
-rw-r--r-- 1 root root 748262 Mar 22 16:51 /usr/lib/x86_64-linux-gnu/libcurl.a
lrwxrwxrwx 1 root root 19 Mar 22 16:51 /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.3 -> libcurl-gnutls.so.4
lrwxrwxrwx 1 root root 23 Mar 22 16:51 /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 -> libcurl-gnutls.so.4.2.0
-rw-r--r-- 1 root root 360488 Mar 22 16:52 /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4.2.0
-rw-r--r-- 1 root root 950 Mar 22 16:51 /usr/lib/x86_64-linux-gnu/libcurl.la
lrwxrwxrwx 1 root root 16 Mar 22 16:51 /usr/lib/x86_64-linux-gnu/libcurl.so -> libcurl.so.4.2.0
lrwxrwxrwx 1 root root 12 Mar 22 16:51 /usr/lib/x86_64-linux-gnu/libcurl.so.3 -> libcurl.so.4
lrwxrwxrwx 1 root root 16 Mar 22 16:51 /usr/lib/x86_64-linux-gnu/libcurl.so.4 -> libcurl.so.4.2.0
-rw-r--r-- 1 root root 381512 Mar 22 16:52 /usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0
> curl --version
curl 7.21.7 (x86_64-unknown-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtmp rtsp smtp smtps telnet tftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz TLS-SRP
好的。不确定系统发生了什么。
所以我去管理员卸载然后重新安装 curl。
现在一切正常。所以看起来卷曲版本不知何故搞砸了。
谢谢。
相关文章:
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 通过选项卡的文本设置QTabWidget顺序
- 如何在提升程序选项中设置矢量<矢量>的默认值<string>
- 错误:必须设置CMake工具才能生成.在工具包选项中配置CMake工具
- 设置QTabWidget中各个选项卡的颜色
- 在 QTabWidget 中动态设置单个选项卡的样式
- 提升::P设置选项无法使所有参数都处于位置状态
- 设置复选框选项C++
- 我可以通过设置工具链文件来替换调用 cmake -G<generator> 选项和调用 vcvarsall.bat吗?
- 在现代CMAKE中设置全球选项
- 如何在 libgit2 中设置结帐选项以使其表现得像"git checkout"
- 转到特定页面后,如何将滑动视图的当前索引设置为选项卡栏"by reference"的当前索引?
- 如何在 QTabWidget 中为选项卡设置布局
- 使用 API 而不是全局配置文件设置 OSM 配置选项
- VS2017:如何在不破坏我设置的过滤器的情况下,以.vcxproj编写每个文件的选项?
- boost::p rogram_options:是否可以将一个选项设置为另一个选项的默认值
- 卷曲很慢(我假设我没有正确设置选项)
- Qt 设置选项卡栏
- 如何创建桌面图标/按钮来启动用户Windows屏幕保护程序,并设置选项
- sane_control_option-无法设置选项