Sending HTTP Requests
# GET
curl http://example.com # Displays output to stdout
curl -o output.html http://example.com # Saves output to file
wget http://example.com # Saves output to file
wget -O output.html http://example.com # Saves output to a specified file
# POST (PUT is similar)
# Headers and JSON body
curl -X POST http://localhost:8081/api/blog \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hi_there_im_a_token" \
-d '{"type": "blog", "slug": "test-post", "content": "test content"}'
# You can source -d from a file
# Example below sources from a file called json (no headers)
curl -X POST http://localhost:3000/confirm -d @path/to/json
# DELETE (Follow POST pattern for headers)
curl -X DELETE http://localhost:8081/api/blog/test-post
Analyzing Requests and Responses
# Identify the host and port
curl -v --silent http://example.com 2>&1 | grep "Connected to"
wget --debug [URL] 2>&1 | grep 'Connecting to'
# View SSL certificate, issuer, dates, etc.
curl -v --silent https://example.com 2>&1 | grep -A 6 "Server certificate"
# View page load time
curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" http://example.com
# Debug a request/response
wget --debug http://example.com
Leave a Reply