Domanda

In Terminal it seems like no difference between the two

echo -en 'first\r\nsecond' and echo -en 'first\n\second'

but in the code without \r it doesn't work

echo -en 'GET /test HTTP/1.1\r\nHost: localhost\r\n\r\n' | nc localhost 9292 

works, but

echo -en 'GET /test HTTP/1.1\r\nHost: localhost\n\n' | nc localhost 9292 

doesn't

anyone can explain why it is?

È stato utile?

Soluzione

Some applications can handle both \r\n (a.k.a. CRLF, carriage return line feed) and \n (a.k.a. LF, line feed) equivalently as newline sequences. Your terminal is an example.

The HTTP/1.1 Specification dictates that HTTP header lines always end with CRLF. So, an HTTP server which adheres to the specification (such as the one you're running on localhost:9292) will not interpret LF by itself as a valid HTTP header line termination sequence.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top