curl 在重定向时获取具有正确名称的文件

curl 在重定向时获取具有正确名称的文件

跟进重定向时如何获取具有正确名称的文件? 答案是,

您可以使用以下方式实现相同的自动化行为curl

curl -JLO ...

但是,我发现它并不适用于所有情况,就像对该答案的评论一样。它curl -JLO 'http://www.vim.org/scripts/download_script.php?src_id=9750'有效,但对另一个网址无效,尽管wget --content-disposition对它有效。故障日志附在下面。

有解决方法/修复吗?

$ curl -vJLO https://jmeter-plugins.org/get/
. . .
< HTTP/1.1 302
< Server: nginx/1.4.6 (Ubuntu)
< Date: Fri, 24 Jun 2022 20:24:57 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/5.5.9-1ubuntu4.25
< Location: https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-manager/1.7/jmeter-plugins-manager-1.7.jar
< 
* Ignoring the response-body
. . .
* Issue another request to this URL: 'https://search.maven.org/remotecontent?filepath=kg/apc/jmeter-plugins-manager/1.7/jmeter-plugins-manager-1.7.jar'
. . .
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x7ffff39685c0)
} [5 bytes data]
> GET /remotecontent?filepath=kg/apc/jmeter-plugins-manager/1.7/jmeter-plugins-manager-1.7.jar HTTP/2
> Host: search.maven.org
> user-agent: curl/7.74.0
> accept: */*
. . .
> GET /maven2/kg/apc/jmeter-plugins-manager/1.7/jmeter-plugins-manager-1.7.jar HTTP/2

. . .
< content-type: application/java-archive
< last-modified: Mon, 20 Dec 2021 12:21:32 GMT
< x-checksum-md5: 5d625388a0fa18cc915dff7951dd1210
< x-checksum-sha1: 4fe37f9a091c35651177071f4bd442be85cbce0c
< via: 1.1 varnish, 1.1 varnish
< accept-ranges: bytes
< date: Fri, 24 Jun 2022 20:24:57 GMT
< age: 2093091
< x-served-by: cache-iad-kcgs7200079-IAD, cache-yyz4546-YYZ
< x-cache: HIT, HIT
< x-cache-hits: 1, 1
< x-timer: S1656102298.881078,VS0,VE2
< content-length: 906099
< 
{ [1034 bytes data]
Warning: Remote filename has no length!
* Failure writing output to destination
} [5 bytes data]
* stopped the pause stream!
  0  884k    0  1034    0     0   1659      0  0:09:06 --:--:--  0:09:06  1659
* Connection #2 to host repo1.maven.org left intact
curl: (23) Failure writing output to destination

相关内容