我尝试了以下命令openssl s_client -connect google.com:443,并能够通过 SSL 与 google.com 连接。
但是当我尝试使用一些资源时,GET /?q=cats HTTP/1.1 <enter> Host google.com <enter><enter>我收到以下消息:
HTTP/1.1 400 Bad Request
Date: Wed, 19 Aug 2015 21:12:02 GMT
Server: Apache
Content-Length: 307
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Request header field is missing ':' separator.<br />
<pre>
Host google.com</pre>
</p>
</body></html>
closed
Run Code Online (Sandbox Code Playgroud)
如果我没有指定任何 HTTP 版本并使用,GET /?q=cats <enter>那么我会得到以下响应。在响应中,我可以看到正确的 URL https://www.google.co.in/?q=cats&gws_rd=cr&ei=yPPUVYeVApGzuATIkpuQCw,如果我在浏览器中使用相同的URL ,则它可以工作。
我是否缺少一些标题或其他内容?
HTTP/1.0 302 Found
Location: https://www.google.co.in/?q=cats&gws_rd=cr&ei=yPPUVYeVApGzuATIkpuQCw
Cache-Control: private
Content-Type: text/html; charset=UTF-8
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Date: Wed, 19 Aug 2015 21:23:20 GMT
Server: gws
Content-Length: 273
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: PREF=ID=1111111111111111:FF=0:TM=1440019400:LM=1440019400:V=1:S=fdzyHaeMMBcBYPPy; expires=Fri, 18-Aug-2017 21:23:20 GMT; path=/; domain=.google.com
Set-Cookie: NID=70=Xxap0a_fYjPIwnvwUuyUqKaT6UH6ZjttA6zv6CYv8qVGMCuOEyNRc8hR2JCi1X_8522QMF2OpsG9dDrWphQh-df0orBmG-DC0WCTF9A_YVJYp3YSgQyap5GlL11EBjff; expires=Thu, 18-
Feb-2016 21:23:20 GMT; path=/; domain=.google.com; HttpOnly
Alternate-Protocol: 443:quic,p=1
Alt-Svc: quic=":443"; p="1"; ma=604800
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="https://www.google.co.in/?q=cats&gws_rd=cr&ei=yPPUVYeVApGzuATIkpuQCw">here</A>.
</BODY></HTML>
read:errno=0
Run Code Online (Sandbox Code Playgroud)
另一种 302 响应。
**GET / HTTP/1.1
Host: www.google.com**
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: https://www.google.co.in/?gfe_rd=cr&ei=7_3UVfDeCuPI8AeMkZzwDQ
Content-Length: 262
Date: Wed, 19 Aug 2015 22:06:39 GMT
Server: GFE/2.0
Alternate-Protocol: 443:quic,p=1
Alt-Svc: quic=":443"; p="1"; ma=604800
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="https://www.google.co.in/?gfe_rd=cr&ei=7_3UVfDeCuPI8AeMkZzwDQ">here</A>.
</BODY></HTML>
Run Code Online (Sandbox Code Playgroud)
当谷歌说
Request header field is missing ':' separator.
Run Code Online (Sandbox Code Playgroud)
它们的实际意思是请求中的标头字段需要使用“:”分隔符。
所以,而不是发送这个:
GET /?q=cats HTTP/1.1<enter>
Host google.com<enter>
<enter>
Run Code Online (Sandbox Code Playgroud)
你需要发送这个:
GET /?q=cats HTTP/1.1<enter>
Host: google.com<enter>
<enter>
Run Code Online (Sandbox Code Playgroud)
(注意:分隔“主机”和“google.com”)
一旦那不碍事,你会得到一个 302:
HTTP/1.0 302 Found
Location: https://www.google.co.in/?q=cats&gws_rd=cr&ei=yPPUVYeVApGzuATIkpuQCw
Run Code Online (Sandbox Code Playgroud)
我实际上在同一个请求中得到了 301:
HTTP/1.1 301 Moved Permanently
Location: https://www.google.com/?q=cats
Run Code Online (Sandbox Code Playgroud)
这些不是错误响应,它们是重定向响应。Google 已听到我们的请求,并希望我们以不同的方式重新请求。就我而言,它告诉我我不应该问“google.com”,我应该问“www.google.com”,下次我应该记住这一点。在您的情况下,它希望您访问 www.google.co.in 并使用不同的查询字符串 - 大概您在印度并且他们希望您访问本地版本的 Google。至于希望您使用不同的查询字符串,好吧,这些是看起来很正常的 Google 查询字符串 (gws_rd, ei) 参数;他们只是在为您整理您的查询。
这是正常的 Web 应用程序行为。您手工制作了一个查询。Web 应用程序 (Google) 不喜欢您查询的某些方面,并重新编写它以更符合您在常规浏览器中搜索“cats”时会发生的情况。然后他们将这个新 URL 交给您的客户端(在本例中为 openssl)并告诉它再次询问。但是由于您是手动执行此操作,因此您没有再次询问,而是将其误解为错误条件。
如果我按照他们的要求进行并重复我的查询,但使用Host: www.google.com代替Host: google.com,我会得到您在搜索猫时所期望的结果。
| 归档时间: |
|
| 查看次数: |
2526 次 |
| 最近记录: |