1

Я узнаю о протоколе HTTP. Я хотел получить результат запроса Google, используя telnet.

Я сделал это так:

telnet google.com 80
Trying 172.217.20.206...
Connected to google.com.
Escape character is '^]'.
GET /search?q=hello+world http/1.1
host: google.com

Но ответ совсем не то, что я хочу

HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Content-Length: 1555
Date: Thu, 13 Apr 2017 21:48:39 GMT

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 400 (Bad Request)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>400.</b> <ins>That’s an error.</ins>
  <p>Your client has issued a malformed or illegal request.  <ins>That’s all we know.</ins>
Connection closed by foreign host.

Что такого плохого в моей просьбе?

2 ответа2

3

Что такого плохого в моей просьбе?

Вам не нужен http/1.1

$ telnet google.com 80
Trying 216.58.198.174...
Connected to google.com.
Escape character is '^]'.
GET /search?q=hello+world

HTTP/1.0 302 Found
Location: http://www.google.co.uk/search?q=hello+world&gws_rd=cr&ei=rQbwWO-EFuPGgAbQsqvoCQ
Cache-Control: private
Content-Type: text/html; charset=UTF-8
P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."
Date: Thu, 13 Apr 2017 23:15:57 GMT
Server: gws
Content-Length: 285
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: NID=101=OFb36GmHOF7h2VCg_9pDdxY1vDrp5JYXjQOEIpjyIR1LJt228TZHgfC_pfNeFAQsBvR1REMMBXDkJoyuI45KYt1u3OrSvWQu7guevtsYF2RGJiTUqx9gZLcxbfXcNdn6; expires=Fri, 13-Oct-2017 23:15:57 GMT; path=/; domain=.google.com; HttpOnly

<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="http://www.google.co.uk/search?q=hello+world&amp;gws_rd=cr&amp;ei=rQbwWO-EFuPGgAbQsqvoCQ">here</A>.
</BODY></HTML>
Connection closed by foreign host.
$
1

http/1.1 в вашем запросе должен быть в верхнем регистре, т.е. HTTP/1.1 .

Смотрите этот пост переполнения стека .

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .