Skip to content

Instantly share code, notes, and snippets.

@abiydv
Created August 30, 2021 01:11
Show Gist options
  • Save abiydv/c09de26f706ab68670885bd2d3d2d959 to your computer and use it in GitHub Desktop.
Save abiydv/c09de26f706ab68670885bd2d3d2d959 to your computer and use it in GitHub Desktop.
Curl Snippets
curl -F "firstname=John" -F"lastname=Doe" "https://httpbin.org/post" -F"file=@file.txt"
{
"args": {},
"data": "",
"files": {
"file": "This is a test file\n"
},
"form": {
"firstname": "John",
"lastname": "Doe"
},
"headers": {
"Accept": "*/*",
"Content-Length": "408",
"Content-Type": "multipart/form-data; boundary=------------------------afd9220cdc8dae3d",
"Host": "httpbin.org",
"User-Agent": "curl",
"X-Amzn-Trace-Id": "Root=1-60ec24b5-1cdf63422773e29d6c0b653f"
},
"json": null,
"url": "https://httpbin.org/post"
}
curl -F "firstname=John" -F "lastname=Doe" "https://httpbin.org/post"
{
"args": {},
"data": "",
"files": {},
"form": {
"firstname": "John",
"lastname": "Doe"
},
"headers": {
"Accept": "*/*",
"Content-Length": "248",
"Content-Type": "multipart/form-data; boundary=------------------------e41227aceee312a6",
"Host": "httpbin.org",
"User-Agent": "curl",
"X-Amzn-Trace-Id": "Root=1-60ec23d7-3a82be0162af35456010c778"
},
"json": null,
"url": "https://httpbin.org/post"
}
curl "https://httpbin.org/post" -d "firstname=John&lastname=Doe"
{
"args": {},
"data": "",
"files": {},
"form": {
"firstname": "John",
"lastname": "Doe"
},
"headers": {
"Accept": "*/*",
"Content-Length": "27",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl",
"X-Amzn-Trace-Id": "Root=1-60ec27f5-4d461f2d3bbf20ed16291ed3"
},
"json": null,
"url": "https://httpbin.org/post"
}
curl https://httpbin.org/cookies -b "country=GB; language=EN; debug=1"
{
"cookies": {
"country": "GB",
"debug": "1",
"language": "EN"
}
}
cat cookies.txt
httpbin.org FALSE / FALSE 0 country GB
httpbin.org FALSE / FALSE 0 language EN
httpbin.org FALSE / FALSE 0 source file
httpbin.org FALSE / FALSE 0 debug 2
curl https://httpbin.org/cookies -b cookies.txt
{
"cookies": {
"country": "GB",
"debug": "2",
"language": "EN",
"source": "file"
}
}
curl https://httpbin.org/headers -H "CustomHeader1: value1" -H "CustomHeader2: value2"
{
"headers": {
"Accept": "*/*",
"Customheader1": "value1",
"Customheader2": "value2",
"Host": "httpbin.org",
"User-Agent": "curl/7.73.0",
"X-Amzn-Trace-Id": "Root=1-5fadb190-26af70e1691093c76d180401"
}
}
curl -v https://httpbin.org/ip -s -o /dev/null | grep ">"
* Trying 3.211.1.78:443...
* Connected to httpbin.org (3.211.1.78) port 443 (#0)
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x1da3b7de150)
} [5 bytes data]
> GET /ip HTTP/2
> Host: httpbin.org
> user-agent: curl/7.73.0
> accept: */*
curl https://httpbin.org/cookies/set/locale/en_GB -c cookies.txt -b cookies.txt -L
{
"cookies": {
"locale": "en_GB"
}
}
curl https://httpbin.org/cookies/set/locale/en_GB -c cookies.txt
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/cookies">/cookies</a>. If not click the link.
cat cookies.txt
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
httpbin.org FALSE / FALSE 0 locale en_GB
curl -D - https://httpbin.org/ip -s -o /dev/null
HTTP/2 200
date: Thu, 12 Nov 2019 19:10:39 GMT
content-type: application/json
content-length: 32
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true
curl -I https://httpbin.org/ip
HTTP/2 200
date: Thu, 12 Nov 2019 19:08:13 GMT
content-type: application/json
content-length: 32
server: gunicorn/19.9.0
access-control-allow-origin: *
access-control-allow-credentials: true
while read url; do curl $url -w " %{response_code} | $url --> %{redirect_url} \n" -s -o /dev/null; done < urls.txt
301 | https://httpbin.org/status/301 --> https://httpbin.org/redirect/1
302 | https://httpbin.org/status/302 --> https://httpbin.org/redirect/1
307 | https://httpbin.org/status/307 --> https://httpbin.org/redirect/1
curl https://httpbin.org/status/302 -w "%{response_code} %{redirect_url}" -s -o /dev/null
302 https://httpbin.org/redirect/1
curl https://httpbin.org/headers -A "bob-the-builder"
{
"headers": {
"Accept": "*/*",
"Host": "httpbin.org",
"User-Agent": "bob-the-builder",
"X-Amzn-Trace-Id": "Root=1-5fadb05b-490211b54febef30592912b5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment