我安装了支持 http2.0 协议的 curl,我在版本信息中看到了 HTTP2。
$ ./curl --version
curl 7.42.1 (x86_64-apple-darwin14.5.0) libcurl/7.42.1 OpenSSL/1.0.2a zlib/1.2.5 nghttp2/0.7.13
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets
Run Code Online (Sandbox Code Playgroud)
但是当我通过 curl(使用详细模式)发送请求时,我看到了 http1.1 协议。
./curl -v --http2 https://http2bin.org/get
* Trying 104.131.161.90...
* Connected to http2bin.org (104.131.161.90) port 443 (#0)
* ALPN, offering h2-14
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set …Run Code Online (Sandbox Code Playgroud) 使用libcurl. 下载源 tar 文件并编译,直到这里一切正常。
遵循这个进度函数示例,它没有按预期工作。
设置显示进度的回调函数
curl_easy_setopt(m_curl, CURLOPT_XFERINFOFUNCTION, &FileTransfer::progressCallback);
curl_easy_setopt(m_curl, CURLOPT_NOPROGRESS, 0);
Run Code Online (Sandbox Code Playgroud)
这是
int FileTransfer::progressCallback(void* clientp, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow)
{
fprintf(stderr, "UP: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
" DOWN: %" CURL_FORMAT_CURL_OFF_T " of %" CURL_FORMAT_CURL_OFF_T
"\r\n",
ulNow, ulTotal, dlNow, dlTotal);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是打印
........
UP: 4233172 of 0 DOWN: 0 of 2588672
UP: 4233172 of 0 DOWN: 0 of 2588672
UP: 4233172 of 0 DOWN: 0 of 2588672
UP: …Run Code Online (Sandbox Code Playgroud) 我想挂载 FTP 驱动器,但我的 FTP 密码包含“@”。
我输入命令:
curlftpfs myaccount:my@password@thefptserver.com mnt/my_ftp
Run Code Online (Sandbox Code Playgroud)
但它给我“连接到 ftp 时出错:无法解析主机:密码”
我该如何解决这个问题,在 '' 中包装东西的组合不起作用,或者它们被完全忽略
我已将zip包含 txt 文件的 WinRAR 压缩文件上传到我的 github 测试存储库中,如何zip使用下载该文件curl?
我试过:
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
return written;
}
void Download(std::string url)
{
CURL *curl_handle;
static const char *pagefilename = "data.zip";
FILE *pagefile;
curl_global_init(CURL_GLOBAL_ALL);
/* init the curl session */
curl_handle = curl_easy_init();
/* set URL to get here */
curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
/* Switch on full protocol/debug output while testing …Run Code Online (Sandbox Code Playgroud) curl -I 给出 503 错误,而curl -v 给出 200 错误。根本原因是什么?
例如-
curl -I -k https://myurl
HTTP/1.1 503 Service Unavailable
Run Code Online (Sandbox Code Playgroud)
curl -k -v https://myurl
HTTP/1.1 200 OK
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个快速脚本,可以使用来自 CloudFlare 的新 1.1.1.1 DNS over HTTPS 公共 DNS 服务器进行 dns 查找。
在这里查看他们的文档https://developers.cloudflare.com/1.1.1.1/dns-over-https/json-format/我不确定我做错了什么以及为什么我收到 415 状态代码(415 不支持的内容类型)。
这是我的脚本: #!/usr/bin/env python import requests import json from pprint import pprint
url = 'https://cloudflare-dns.com/dns-query'
client = requests.session()
json1 = {'name': 'example.com','type': 'A'}
ae = client.get(url, headers = {'Content-Type':'application/dns-json'}, json = json1)
print ae.raise_for_status()
print ae.status_code
print ae.json()
client.close()
Run Code Online (Sandbox Code Playgroud)
这是输出:
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://cloudflare-dns.com/dns-query
Run Code Online (Sandbox Code Playgroud)
对于 json 响应(我相信):
raise ValueError("No JSON object could be decoded") …Run Code Online (Sandbox Code Playgroud) curl ×3
c++ ×2
http ×2
http2 ×2
libcurl ×2
c ×1
curlftpfs ×1
dns ×1
http-headers ×1
httprequest ×1
json ×1
multiplexing ×1
openssl ×1
osx-yosemite ×1
passwords ×1
sftp ×1
windows ×1