Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to test a webserver with some HTTP request written in a file.

GET / HTTP/1.1\r\n\r\n

Right now I'm feeding that file to netcat like this:

cat files | nc localhost 80

However, the \r\n in the files are transfered directly to webserver(resulting in 4 chars, i.e. '\','r','\','n'). How can I feed that file so that chars are escaped correctly?

share|improve this question

migrated from stackoverflow.com Sep 29 '11 at 11:03

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 0 down vote accepted

\r\n are the codes used in a printf statement to generate CarridgeReturn/NewLine line endings used by DOS/Windows.

As you are using cat, you are using some variant of unix which only uses \n as line end. BUT you don't have to have that char appear in the file. Just try removing those values (leaving a real Newline at the end of the line).

Example test file now =

GET / HTTP/1.1
  blah-blah

GET / HTTP/1.1
  blah2

OR if you really must interpret the \r\n values embedded in the file, you can interpret the file with the printf utiltity, i.e.

$ cat printf_inputtest.txt
GET / HTTP/1.1\r\n\r\n
GET / HTTP/1.1\r\n\r\n
$ printf "$( < printf_inputtest.txt )"
GET / HTTP/1.1


GET / HTTP/1.1

$ 

I hope this helps.

share|improve this answer
    
@Usavich : please see my final edits. I believe I have solved your problem exactly as requested. Good luck. –  shellter Sep 29 '11 at 2:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.