7

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.

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>

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

--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?

Fei Xue
  • 1,995
  • 5
  • 19
  • 29
  • It looks like the content of the "200 OK" response is "return=fail&error=Configuration doesn't exist", so it doesn't look like this has worked at all. Are you sure that URL is OK? – Ernest Friedman-Hill May 17 '12 at 04:02
  • I think the url has no problem. It seems there are TWO responses. The first one (return=fail&error=Configuration doesn't exist) is what i expected, but the second one is not. – Fei Xue May 17 '12 at 04:10

3 Answers3

5

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.

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.

Davide Berra
  • 6,387
  • 2
  • 29
  • 50
1

Try replacing & with &amp;.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
gogol
  • 11
  • 1
0

The code at the URL you are accessing is printing some text:

return=fail&error=Configuration doesn't exist

But then your code continues on to print a HTTP 400 error. Probably you forgot to abort after printing the response, and so your code goes on to print the HTTP 400 as well.

Malvineous
  • 25,144
  • 16
  • 116
  • 151