Play with netcat and cURL to make HTTP request

E Ma
Nov 13, 2020

--

HTTP stands for Hypertext Transfer Protocol. It is rules for data communication in WWW(Web Wide Web).

Components of a request

In order to make a http request, we need to at least specify:

  1. Request method — what is the type of request we are making.
  2. URI — which resource to apply the request, including protocol and host name.
  3. Header — additional information about the request, client to the server.

Use netcat to create mock server

To checkout the usage of netcat:

man nc

Create a mock server on port 1000:

nc -l 1000 

-l stands for listen, tells netcat to listen to the specific port number you provided.

Use cURL to make a http request

To checkout the usage of cCRL:

curl --help

To make a request:

curl localhost:1000 -H multipart/form-data -F name=Daisy
  • -X specify the request method
  • -H specifies the request header
  • -F specifics the form data

Once your request is send, your will receive request detail in your mock service like so:

POST / HTTP/1.1Host: localhost:1000User-Agent: curl/7.64.1Accept: */*Content-Length: 144Content-Type: multipart/form-data; boundary=------------------------5438f201a4f68776--------------------------5438f201a4f68776Content-Disposition: form-data; name="name"Daisy--------------------------5438f201a4f68776--

--

--