7

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?
1
  • Pretty sure that should be GET /232 but your webserver might be tolerant... Commented Oct 21, 2022 at 7:09

1 Answer 1

8
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.

Sign up to request clarification or add additional context in comments.

5 Comments

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?
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
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?
see the accepted answer here stackoverflow.com/questions/6004298/… and notice the difference between HTTP 1.0 and HTTP 1.1
normally you should use nc -C to send CRLF instead of LF line endings. Never seen nc interpret \n, does it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.