首页 > 解决方案 > curl 无法通过授权下载

问题描述

我正在尝试从本地http服务器(ip cam)下载。

通过浏览器,它可以正常工作http://user:pass@192.168.1.5/cgi-bin/snapshot.cgi。我得到图像成功。

但随后使用 curl 命令

curl -v -L --digest --negotiate --anyauth --user user:pass "http://192.168.1.5/cgi-bin/snapshot.cgi"

我明白了:

*   Trying 192.168.1.5:80...
* TCP_NODELAY set
* Connected to 192.168.1.5 (192.168.1.5) port 80 (#0)
> GET /cgi-bin/snapshot.cgi HTTP/1.1
> Host: 192.168.1.5
> User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Connection: close
< Content-Length: 0
< WWW-Authenticate: Digest realm="Login to XU1I0705675M1", qop="auth", nonce="d9f03251-2779-4c13-8ad5-98105c9e6c5f", opaque=""
<
* Excess found: excess = 2 url = /cgi-bin/snapshot.cgi (zero-length body)
* Closing connection 0
* Issue another request to this URL: 'http://192.168.1.5/cgi-bin/snapshot.cgi'
* Hostname 192.168.1.5 was found in DNS cache
*   Trying 192.168.1.5:80...
* TCP_NODELAY set
* Connected to 192.168.1.5 (192.168.1.5) port 80 (#1)
* Server auth using Digest with user 'admin'
> GET /cgi-bin/snapshot.cgi HTTP/1.1
> Host: 192.168.1.5
> Authorization: Digest username="admin",realm="Login to XU1I0705675M1",nonce="d9f03251-2779-4c13-8ad5-98105c9e6c5f",uri="/cgi-bin/snapshot.cgi",cnonce="8802bd2d1b65ff9477ba713e40547c32",nc=00000001,response="cbd9b8472c864caee51b75f3f53a13d7",qop="auth"
> User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0
> Accept: */*
>
* Received HTTP/0.9 when not allowed

* Closing connection 1
curl: (1) Received HTTP/0.9 when not allowed

在这种情况下,如何让 curl 获得授权?

编辑:+版本:

curl --version
curl 7.70.0 (x86_64-pc-win32) libcurl/7.70.0 OpenSSL/1.1.1g (Schannel) zlib/1.2.11 brotli/1.0.7 WinIDN libssh2/1.9.0 nghttp2/1.40.0
Release-Date: 2020-04-29
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile MultiSSL NTLM SPNEGO SSL SSPI TLS-SRP UnixSockets brotli libz

标签: curl

解决方案


您可能不得不强制curl接受(意外)降级--http0.9

顺便说一句,从例如https://github.com/cloudflare/quiche/issues/248curl来看,如果我正确阅读了这个问题,这可能是因为服务器没有完全遵守协议并跳闸。


推荐阅读