这件事让我心烦意乱。我正在尝试将两个不同的主机文件下载到一个文件中,如果我依次执行此操作,那么一切都很好,但是当我将第一个文件附加到第二个文件时,^M主机文件的每一行都会出现一个奇怪的字符。
在这里举一个真实的例子我正在做什么
wget https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -O /etc/hosts && curl -s "https://raw.githubusercontent.com/CHEF-KOCH/CKs-FilterList/master/HOSTS/CK's-Spotify-HOSTS-FilterList.txt" >> /etc/hosts
Run Code Online (Sandbox Code Playgroud)
但是当我单独这样做时,所以
curl -s "https://raw.githubusercontent.com/CHEF-KOCH/CKs-FilterList/master/HOSTS/CK's-Spotify-HOSTS-FilterList.txt" > /tmp/hosts
Run Code Online (Sandbox Code Playgroud)
现在/tmp/hosts完全正常
为什么会发生这种情况?为什么当我单独下载文件时,我没有得到错误的换行符,但当我将它们合并时,却得到了错误的换行符。它应该是0x0a而不是0x0a0x0d,为什么会发生这种情况?
如果您需要查看正在下载的文件,可以访问命令中的链接:
编辑:我尝试仅将第二个主机文件附加到哑主机文件中,并且发生了同样的情况,因此我们可以忽略第一个文件是问题的原因
我有一个客户,他的客户使用第三方票据交换所来接收发票。我们可以通过将数据导出到 XML、访问特定网站并上传文件来手动完成此操作。相关的 HTML 表单如下所示:
<form border=0
method="POST"
action="/server?request=send"
enctype="multipart/form-data"
id="uploadform"
name="uploadform"
onsubmit="return checkUpload()">
<H2>Upload</H2>
<p>Server directory:<br>
<input type="text"
id="directory"
name="directory"
value="./"
size="30"></p>
<p>Local file to be uploaded:<br>
<input type="file"
id="file"
name="file"
size="40"></p>
<p><input type="submit" value="Send"></p>
</form>
Run Code Online (Sandbox Code Playgroud)
使用他们的网络界面手动提交效果很好。我正在尝试编写一个快速工具,使用它为我们提交表单curl. 我尝试了很多不同的尝试,但到目前为止,每一次,虽然我得到“文件已成功上传”HTML 响应,但他们得到的文件是空的。
我们最初开始尝试使用,curl是因为票据交换所公司建议我们这样做。他们给出的例子是这样的:
curl -i -k -H "Content-Type:application/octet-stream" \
-d @test.txt -u username:password \
https://example.com/server?request=send?filename=test.txt?directory=DX001
Run Code Online (Sandbox Code Playgroud)
当这不起作用时,我开始查看上面表单中的代码,并尝试以下操作(与 XML 文件位于同一目录中):
curl -F "request=send" -F "directory=DX001" -F "file=33823.xml" \
-u username:password -F "enctype=\"multipart/form-data\"" \
-F "id=\"uploadform\"" https://example.com/server
Run Code Online (Sandbox Code Playgroud)
当这不起作用时,我想我应该尝试绝对路径,即使我位于同一目录中:
curl -F …Run Code Online (Sandbox Code Playgroud) 我想找到一种更简单的方法来从私有 GitHub 存储库获取文件。
我通过在 GitHub 上创建个人访问令牌来下载文件curl,然后像这样使用它:
curl https://MY_TOKEN@raw.githubusercontent.com/accountName/repoName/branchName/fileName.txt
Run Code Online (Sandbox Code Playgroud)
这对我有用,但是我想知道是否有更简单的方法,也许使用 SSH?我不介意输入 SSH 密码,因为它似乎比创建访问令牌更方便。我已经可以在 GitHub 上成功验证:
$ ssh -T git@github.com
# Attempts to ssh to GitHub
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用curlSSH URL 时,出现以下错误:
curl ssh://git@github.com:accountName/repoName/branchName/fileName.txt
curl: (3) URL using bad/illegal format or missing URL
Run Code Online (Sandbox Code Playgroud)
我尝试了本文中描述的其他一些方法,但无济于事。
有任何想法吗?
可能的重复:
Wget 需要登录的页面
我想从http://mbr.nlm.nih.gov/Download/MetaMapped_Medline/2011/下载文件。但是,为了下载文件,我需要输入密码和用户名,这些都是通过 HTTP 表单接受的。
有没有办法使用命令行输入密码/用户名?
我忘记在curl操作后使用> filename。
\n\nLinux 控制台提供连续的垃圾数据(希望在控制台上下载并显示内容)。
\n\n我们怎样才能停止这个过程(ctrl-c 不起作用)?
\n\n获得像这样的连续输出:
\n\n\xc3\x8e\xc3\xbeH2\xc3\x9d\xc2\xbe\xc3\xa0#qs\xc3\xbd\xc2\xbc\xc2\xb0-s\xc3\xa1G\xc3\xa2v\xc3\xa2z\xc3 \xac#\xc3\xa9\xc3\xac\xc2\xbc\xc3\x84\xc3\xba\xc3\x81N\\t1\xc3\x83\n}$ZXGc\xc3\xb4\xc2\xb0
\n\n执行如下
\n\ncurl http://example.com/file.tgz\nRun Code Online (Sandbox Code Playgroud)\n\n代替
\n\ncurl http://example.com/file.tgz > mongo.tgz\nRun Code Online (Sandbox Code Playgroud)\n 我正在尝试将整个文件夹(包括它的子文件夹和文件)从 Windows 批处理 (.bat) 文件上传到我服务器上的文件夹。
以下是我对上传部分的命令...
curl -T E:\Server\bootstrap3\_gh_pages\ -u USER:PASSWORD ftp://domain.com/bootstrap/
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误
curl: Can't open 'E:\Server\bootstrap3\_gh_pages\'!
curl: try 'curl --help' for more information
Run Code Online (Sandbox Code Playgroud)
如果我尝试只做 1 个文件,它工作正常,我需要以某种方式循环并执行所有文件夹和文件,请问有什么帮助吗?
我在谷歌上搜索并尝试了几个不太好的例子,但在这个确切的问题上还没有运气
curl -L http://download.transmissionbt.com/files/transmission-2.80.tar.xz -s -o - | tar -xf -
Run Code Online (Sandbox Code Playgroud)
错误:
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,它可以提取存档:
curl -LO http://download.transmissionbt.com/files/transmission-2.80.tar.xz
tar xf transmission-2.80.tar.xz
Run Code Online (Sandbox Code Playgroud)
为什么管道不起作用?
我想在使用代理时将自定义标头发送到主机。看看下面的例子。用例子解释情况更容易。
这按预期工作正常:
curl https://www.cloudflare.com/
Run Code Online (Sandbox Code Playgroud)
当我选择通过向curl提供主机的IP地址来避免使用DNS时:
curl http://198.41.214.163/
Run Code Online (Sandbox Code Playgroud)
网站给我这个错误页面 -->
“不允许直接 IP 访问。您请求的 IP 地址属于 CloudFlare 网络的一部分。必须提供有效的主机标头 才能访问所需的网站。”
如果我们提供正确的主机头名称,它将在不使用 DNS 的情况下再次正常工作:
curl --header "Host: cloudflare.com" http://198.41.214.163/
Run Code Online (Sandbox Code Playgroud)
但是,当我在使用代理隧道时执行相同操作时,curl 不会将标头发送到主机,因此我收到来自主机的“不允许直接 IP 访问”错误:
curl --proxy "http://PROXY_IP:PORT" --header "Host: cloudflare.com" http://198.41.214.163/
Run Code Online (Sandbox Code Playgroud)
我怎样才能克服这个问题?
我正在运行Ubuntu 16.04.4 LTS。我有以下版本:
root@e816b85d954d:/# http --debug
HTTPie 0.9.9
Requests 2.9.1
Pygments 2.1
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609]
/usr/bin/python
Linux 4.4.0-116-generic
root@e816b85d954d:/# curl --version
curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets
Run Code Online (Sandbox Code Playgroud)
curl 工作正常:
$ curl https://mysite
Run Code Online (Sandbox Code Playgroud)
但是 …
我正在 Linux 上使用 Opera 浏览器下载 ISO 映像:
我通过右键单击获得下载链接:
curl然后我想在Linux控制台上使用,但我不能:
curl -O https://software-download.microsoft.com/db/Win10_1903_V2_English_x64.iso?t=3bbd00d6-f352-44fe-8d54-39823648e16f&e=1570698933&h=9209eec4d6644bf387d305a0fcc20fd3
Run Code Online (Sandbox Code Playgroud)
该curl命令几乎立即返回,没有任何有用的下载。我想知道为什么会发生这种情况?
我的问题很简单 -当curl执行多个请求时,有没有办法显示每个URL的curl的单独退出状态?
让我们假设我需要检查站点a.com、b.com并c.com查看它们:
000,我需要显示curl的exit code。注意 - a.com、b.com、c.com在此代码/问题中用作示例。在真实的脚本中,我确实有一个有效的 URL 列表 - 其中超过 400 个具有非重叠模式 - 并且它们返回各种 HTTP 代码 - 200/4xx/5xx 以及 000。
000 是curl 无法建立连接的情况,但提供退出代码以了解阻止其建立连接的原因。就我而言,还有许多退出代码 - 6、7、35、60。
我尝试运行以下代码
unset a
unset rep
a=($(curl -s --location -o /dev/null -w "%{response_code}\n" {https://a.com,https://b.com,https://a.com}))
rep+=("$?")
printf '%s\n' "${a[@]}"
echo
printf '%s\n' "${rep[@]}"
Run Code Online (Sandbox Code Playgroud)
虽然上述代码返回每个单独请求的 HTTP 返回代码,但仅显示最后一个请求的退出代码。
000
000
000
60
Run Code Online (Sandbox Code Playgroud)
当我提供多个 URL 进行卷曲时,我确实需要能够记录单独的退出代码。这个问题有解决方法/解决方案吗?
一些附加信息:目前,我将所有 URL 放入一个数组中,并通过它运行一个循环,分别检查每个 URL。然而,浏览 …
我的phpinfo();节目 cURL 安装在服务器上,但是当我使用该命令时,/usr/bin/curl它返回/bin/sh: 1: /usr/bin/curl: not found.
现在,当我输入时which curl,它不会返回任何内容。
任何想法如何正确找到cURL的路径?
我想在 zsh 中运行curl 命令。
curl -X GET "https://api.cloudflare.com/client/v4/zones/<ZONE>" \
-H "Content-Type:application/json" \
-H "Authorization: Bearer <TOKEN>"
Run Code Online (Sandbox Code Playgroud)
但是当运行这个我得到
{"success":false,"errors":[{"code":9106,"message":"Missing X-Auth-Email header"},{"code":9107,"message":"Missing X-Auth-Key header"}],"messages":[],"result":null}curl: (3) URL using bad/illegal format or missing URL
zsh: command not found: -H
zsh: command not found: -H
Run Code Online (Sandbox Code Playgroud)
除了错误响应之外。为什么到我zsh: command not found: -H这里就意味着该选项-H被忽略了。