telnet发送http请求

问题描述:

我使用telnet发送http请求,如下所示:

I am using telnet to send a http request , like this:

telnet> open 192.168.4.135 8087
Trying 192.168.4.135...
Connected to 192.168.4.135.
Escape character is '^]'.
POST /rpc/ HTTP/1.1
HOST:192.168.4.135:8087
Content-length:18
Content-type:application/x-http-form-urlencoded

action=loadrsctype
HTTP/1.1 200 OK
Date: Thu, 17 May 2012 03:52:53 GMT
Content-Length: 45
Content-Type: text/html; charset=ISO-8859-1

return=fail&error=Configuration doesn't existHTTP/1.1 400 Bad Request
Content-Type: text/html
Connection: close
Date: Thu, 17 May 2012 03:52:53 GMT
Content-Length: 94

<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
</BODY></HTML>
Connection closed by foreign host.

响应代码为200,但为什么会出现这样的段落:

the response code is 200 , but why there is a paragraph like this :

HTTP/1.1 400 Bad Request
Content-Type: text/html
Connection: close
Date: Thu, 17 May 2012 03:52:53 GMT
Content-Length: 94

<HTML><HEAD>
<TITLE>400 Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
</BODY></HTML>

这是服务器或telnet本身的输出?如何避免显示这个?

This is the output of the server or telnet itself ? How to avoid to show this ?

- 更新 -
当我将HTTP / 1.1更改为http / 1.1时,我得到了正确的权利响应。
现在我想知道这是协议的要求还是与服务器的实现有关?

--update-- When i change "HTTP/1.1" to "http/1.1", i get the right response. Now i wonder wheather this is requirement of protocol or related with the implementation of the server?

HTTP 1.1 中,所有连接都被视为持久性除非另有声明。

In HTTP 1.1, all connections are considered persistent unless declared otherwise.

然后......我认为服务器正在接收一些虚假的换行符,并回复错误请求

Then... I think the server is receiving some spurious newline char and reply with a Bad Request.

如果您使用 http / 1.1 而不是 HTTP / 1.1 可以使版本回退到版本 1.0 默认情况下不是持久的,并且在 200 OK 响应后它会丢弃连接。

If you use http/1.1 instead of HTTP/1.1 could make fallback the version to the version 1.0 that's not persistent by default and after the 200 OK response it drops the connection.