Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何获取HTTPS请求的响应号_Linux_Shell_Curl_Https_Wget - Fatal编程技术网

Linux 如何获取HTTPS请求的响应号

Linux 如何获取HTTPS请求的响应号,linux,shell,curl,https,wget,Linux,Shell,Curl,Https,Wget,我想使用Linux命令来获取HTTPS请求的响应号,而不是HTTP请求。根据我目前的知识,wget和curl可以实现目标 例如,给定地址,我打算使用以下命令: 使用curl:curl-Ihttps://asunnot.oikotie.fi/vuokrattavat-asunnot/espoo/13874872 使用wget:wget--spider-S'https://asunnot.oikotie.fi/vuokrattavat-asunnot/espoo/13874872“ 这两个请求都

我想使用Linux命令来获取HTTPS请求的响应号,而不是HTTP请求。根据我目前的知识,
wget
curl
可以实现目标

例如,给定地址,我打算使用以下命令:

  • 使用curl:
    curl-Ihttps://asunnot.oikotie.fi/vuokrattavat-asunnot/espoo/13874872
  • 使用wget:
    wget--spider-S'https://asunnot.oikotie.fi/vuokrattavat-asunnot/espoo/13874872“
这两个请求都得到了响应,响应为HTTP/1.1405 Not Allowed。但当我用浏览器(如Chrome或Firefox等)尝试该地址时,页面确实可以毫无问题地显示出来


有人能帮忙吗?如何获得正确的响应号而不是第一个直接405

使用
curl
您需要设置
-A,--user-agent
选项,因为某些HTTP服务器/CGI需要填充头
user-agent

curl -I 'https://asunnot.oikotie.fi/vuokrattavat-asunnot/espoo/13874872' -A "Mozilla/5.0"
输出:

HTTP/1.1 200 OK
Date: Tue, 14 Nov 2017 13:56:11 GMT
Content-Type: text/html
Connection: keep-alive
Server: nginx
Vary: Accept-Encoding
X-DB: 5
X-DW: 0
X-DZ: 93.72.75.166
X-VID: 93.72.75.166:14CDB9B4-DE01-3FAA-AFF5-65BC2F771745
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: private, no-cache, no-store, must-revalidate
Edge-Control: no-store, bypass-cache
Surrogate-Control: no-store, bypass-cache

-A,--user-agent

(HTTP)指定要发送到HTTP服务器的用户代理字符串。如果此字段不正确,一些做得很差的CGI将失败 设置为
“Mozilla/4.0”
。要对字符串中的空格进行编码,请使用单引号将字符串括起来。这个可以 当然,也可以使用
-H,--header
选项进行设置


服务器使用HTTP代码405应答,因为它拒绝您发送的
curl
命令的
User-Agent
头。从服务器配置或网站应用程序本身来看,这显然是一种不良行为。服务器应该用HTTP 400进行应答

无论如何,对于给定的URL,以下内容可以正常工作:

curl -I -H "User-Agent: Mozilla/5.0" <url>
curl-I-H“用户代理:Mozilla/5.0”
详细说明正确的回复号码