【问题标题】:wget breaking with content-dispositionwget 打破内容处置
【发布时间】:2016-09-10 07:38:09
【问题描述】:

我正在尝试从以下网站下载通过 Content-Disposition:attachment 发送的 kml 文件:

http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia

使用 wget 和 curl 命令:

wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia

curl -O -J -L http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia

但是,它不会保存正在发送的文件,而是仅保存 html 内容,并且在传输结束时会卡住。终端返回是:

$wget --content-disposition http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia
[1] 32260
[2] 32261
[3] 32262
work@Aspire-V3-471:~$ --2016-05-13 19:37:54--  http://waterwatch.usgs.gov/index.php?m=real
Resolving waterwatch.usgs.gov (waterwatch.usgs.gov)... 2001:49c8:0:126c::56, 137.227.242.56
Connecting to waterwatch.usgs.gov (waterwatch.usgs.gov)|2001:49c8:0:126c::56|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.php?m=real.5’

    [  <=>                                                                                                                                                  ] 41.637       174KB/s   in 0,2s   

2016-05-13 19:37:55 (174 KB/s) - ‘index.php?m=real.5’ saved [41637]

而且它们很粘,我需要按 Ctrl+C。 因为我得到的标题是

HTTP/1.1 200 OK
Date: Sat, 14 May 2016 00:19:21 GMT
Content-Disposition: attachment; filename="real_ia.kml"
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: application/vnd.google-earth.kml+xml
X-Frame-Options: SAMEORIGIN

我希望下载“real_ia.kml”文件。 使用 curl 命令可以得到类似的结果。

为什么会卡住,只下载 HTML 内容?

【问题讨论】:

    标签: linux curl wget content-disposition


    【解决方案1】:

    &amp; 符号被解释为 shell 特殊字符,它导致命令在后台运行(fork)。所以你应该escape or quote他们:

    curl -O -J -L 'http://waterwatch.usgs.gov/index.php?m=real&w=kml&r=us&regions=ia'
    

    在上面的命令中,我们使用了full quoting

    您的输出中的以下几行表示正在将三个命令分叉到后台:

    [1] 32260
    [2] 32261
    [3] 32262
    

    左边的数字(括号内)是工作编号。您可以通过键入fg N 将作业置于前台,其中N 是作业的编号。右边的数字是进程 ID。

    【讨论】:

    • Ruslan Osmanov,你拯救了这一天!现在一切都使用命令运行:curl -O -J -L http://waterwatch.usgs.gov/index.php?m=real\&amp;w=kml\&amp;r=us\&amp;regions=ia(只是在这里发布以使其他人清楚)非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多