6

I am trying to convert a curl command (post) to a netcat command.

I already figured out how to GET/DELETE things like

curl -v http://localhost:1234/232

in netcat:

nc localhost 1234
GET 232
HOST: localhost

but I dont know how to POST something

For example: I want to save to value 2300 in my path 123

curl -v --data "val=2300" http://localhost:1234/123

and in netcat:
nc localhost 1234
POST 123
HOST: localhost

but where do i write my value?
user3717963
  • 179
  • 1
  • 3
  • 8

1 Answers1

6
nc localhost 1234
POST /123 HTTP/1.0
Content-Length: 8
Content-Type: application/x-www-form-urlencoded
\n
val=2300

Content-Length is set to let the server know how much data you're going to send (string length of "val=2300"). Content-Type is to let the server know in which format the data is (form-encoded). The \n is the HTTP separation character (empty line) between headers and data.

Hans Z.
  • 50,496
  • 12
  • 102
  • 115
  • ah cool. It worked :D. Can you explain me why content-lenght is 8 and why the type is application/x-www-form-urlencoded? and why do i have to add the \n? – user3717963 Jan 02 '15 at 16:50
  • added some stuff by editing the post; curl will set those headers for you automatically based on the `-d` flag; you can check that with `curl -v` – Hans Z. Jan 02 '15 at 16:55
  • last question: is "HOST: localhost" necessary? My teacher just gave me the code and I can type it without it. But when do I have to add it? – user3717963 Jan 02 '15 at 17:10
  • see the accepted answer here http://stackoverflow.com/questions/6004298/when-could-the-http-host-header-be-undefined and notice the difference between HTTP 1.0 and HTTP 1.1 – Hans Z. Jan 02 '15 at 17:15
  • normally you should use nc -C to send CRLF instead of LF line endings. Never seen nc interpret \n, does it? – masterxilo Oct 21 '22 at 07:10