如何从 Windows 命令行执行 HTTP HEAD 请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/217955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:35:03  来源:igfitidea点击:

How to do a HTTP HEAD request from the windows command line?

windowshttpcommand-linewindows-vista

提问by Henning

What's the best way (or tool) on the Windows (Vista) command line to get size and modification time for a file on a remote webserver, without downloading it?

Windows (Vista) 命令行上无需下载即可获取远程 Web 服务器上文件的大小和修改时间的最佳方法(或工具)是什么?

采纳答案by CesarB

On Linux, I often use curl with the --head parameter. It is available for several operating systems, including Windows.

在 Linux 上,我经常使用带有 --head 参数的 curl。它适用于多种操作系统,包括 Windows。

[edit] related to the answer below, gknw.net is currently down as of February 23 2012. Check curl.haxx.se for updated info.

[编辑] 与下面的答案相关,gknw.net 目前在 2012 年 2 月 23 日关闭。检查 curl.haxx.se 以获取更新信息。

回答by Tomalak

There is a Win32 port of wgetthat works decently.

wget有一个运行良好的Win32 端口

PowerShell's Invoke-WebRequest -Method Headwould work as well.

PowerShellInvoke-WebRequest -Method Head也能工作。

回答by Laurence

If you cannot install aditional applications, then you can telnet (you will need to install this feature for your windows 7 by following this) the remote server:

如果您无法安装aditional的应用程序,那么你就可以远程登录(你需要通过以下步骤来安装此功能,您的Windows 7这个)的远程服务器:

TELNET server_name 80

followed by:

其次是:

HEAD /virtual/directory/file.ext

or

或者

GET /virtual/directory/file.ext

depending on if you want just the header (HEAD) or the full contents (GET)

取决于您是只想要标题(HEAD)还是完整的内容(GET)

回答by David Bell

1) See the headers that come back from a GET request

1) 查看从 GET 请求返回的标头

wget --server-response -O /dev/null http://....

1a) Save the headers that come back from a GET request

1a) 保存从 GET 请求返回的标头

wget --server-response -o headers -O /dev/null http://....

2) See the headers that come back from GET HEAD request

2) 查看从 GET HEAD 请求返回的标头

wget --server-response --spider http://....

2a) Save the headers that come back from a GET HEAD request

2a) 保存从 GET HEAD 请求返回的标头

wget --server-response --spider -o headers http://....
  • David
  • 大卫

回答by Vinko Vrsalovic

I'd download PuTTYand run a telnet session on port 80 to the webserver you want

我会下载PuTTY并在端口 80 上运行 telnet 会话到您想要的网络服务器

HEAD /resource HTTP/1.1
Host: www.example.com

You could alternatively download Perland try LWP's HEAD command. Or write your own script.

您也可以下载Perl并尝试 LWP 的 HEAD 命令。或者编写自己的脚本。