KEMBAR78
Curl Tutorial | PPTX
CURL
Ankireddy Polu
cURL ( Client URL)
◦ command line tool and library for transferring data
with URLs
◦ DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP,
IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP,
RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS,
Telnet and TFTP.
◦ curl supports SSL certificates, HTTP POST, HTTP PUT,
FTP uploading, HTTP form based upload, proxies,
HTTP/2, HTTP/3, cookies, user+password
authentication (Basic, Plain, Digest, CRAM-MD5,
NTLM, Negotiate and Kerberos), file transfer
resume, proxy tunneling and more.
Limitations to invoke URLs?
◦ Customers won’t allow install any additional
software on their servers including the browser
plugins.
◦ Restricted access to ports
◦ Instruct the server admins using tools which they
are familiar.
Install cURL
https://bintray.com/artifact/download/vs
zakats/generic/curl-7.73.0-win32-
mingw.zip
brew install curl
Linux MacOS Windows
For Ubuntu
sudo apt update
sudo apt install curl
For centos/RHEL
sudo yum install curl
choco install curl
Invoke-RestMethod
◦ GET
◦ GET with custom headers example
◦ PUT/POST
◦ DELETE
◦ Basic Authentication
◦ API key
◦ File Upload (InFile)
◦ Params
◦ ConvertFrom-JSON, ConvertTo-JSON
Curl
◦ GET
◦ GET with custom headers example
◦ PUT/POST
◦ DELETE
◦ Basic Authentication
◦ API key
◦ File Upload ( -F )
◦ Insecure (-k, --insure)
◦ Config
◦ verbose
Replicating browser requests with cURL
◦ Copy as PowerShell◦ Copy as cURL
Commands
CURL
curl -X GET "https://httpbin.org/image" -H "accept:image/webp" --output c:softwareswebp.webp
curl -X GET "https://httpbin.org/image/png" -H "accept:image/png" --output c:softwarespng.png
curl -s -w "%{http_code}" -X GET "https://httpbin.org/image" -H "accept:image/webp" --output
c:softwareswebp.webp
curl -I -X GET "https://httpbin.org/basic-auth/system/manager" -H "accept: application/json"
curl -u system:manager -X GET "https://httpbin.org/basic-auth/system/manager" -H "accept:
application/json"
curl https://brianiswu-cat-facts-v1.p.rapidapi.com/facts -w "%{http_code}"
curl -H "x-rapidapi-key:1475db38bamsh43c4c98a9ca0578p115c39jsn333977ab7597"
https://brianiswu-cat-facts-v1.p.rapidapi.com/facts
curl -H "x-rapidapi-key:1475db38bamsh43c4c98a9ca0578p115c39jsn333977ab7597"
https://brianiswu-cat-facts-v1.p.rapidapi.com/facts --output c:softwaresoutput.json
curl -v -insecure https://expired.badssl.com/
Commands
CURL + Elasticsearch
curl -X POST
http://localhost:9200/default_umc/_doc -H
"content-type:application/json" --data
'{"user":"anki","country":"india","city":"chennai"}'
curl -X POST
http://localhost:9200/default_umc/_search -H
"content-type:application/json" --data
'{"query":{"term":{"user":"anki"}}}'
curl -X DELETE http://localhost:9200/default_umc/
Commands
Invoke-RestMethod
invoke-restmethod -method GET -Uri https://httpbin.org/image -outfile
c:softwareswebp.webp
invoke-restmethod -method GET -Uri https://httpbin.org/image -header
@{"accept"="image/webp"} -outfile c:softwareswebp.webp
$header = @{"accept"="image/webp"}
invoke-restmethod -method GET -Uri https://httpbin.org/image -header $header -
outfile c:softwareswebp.webp
$credentials = Get-Credential
Invoke-restmethod -cred $credentials -Method GET -Uri https://httpbin.org/basic-
auth/system/manager -outfile c:softwaresout.json
invoke-restmethod -Method GET -uri https://brianiswu-cat-facts-
v1.p.rapidapi.com/facts -Header @{"x-rapidapi-
key"="1475db38bamsh43c4c98a9ca0578p115c39jsn333977ab7597"}
Resources
◦ https://httpbin.org/
◦ https://expired.badssl.com/
◦ https://rapidapi.com/brianiswu/api/cat-facts
◦ https://curlbuilder.com/

Curl Tutorial

  • 1.
  • 2.
    cURL ( ClientURL) ◦ command line tool and library for transferring data with URLs ◦ DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet and TFTP. ◦ curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, HTTP/3, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling and more.
  • 3.
    Limitations to invokeURLs? ◦ Customers won’t allow install any additional software on their servers including the browser plugins. ◦ Restricted access to ports ◦ Instruct the server admins using tools which they are familiar.
  • 4.
    Install cURL https://bintray.com/artifact/download/vs zakats/generic/curl-7.73.0-win32- mingw.zip brew installcurl Linux MacOS Windows For Ubuntu sudo apt update sudo apt install curl For centos/RHEL sudo yum install curl choco install curl
  • 5.
    Invoke-RestMethod ◦ GET ◦ GETwith custom headers example ◦ PUT/POST ◦ DELETE ◦ Basic Authentication ◦ API key ◦ File Upload (InFile) ◦ Params ◦ ConvertFrom-JSON, ConvertTo-JSON
  • 6.
    Curl ◦ GET ◦ GETwith custom headers example ◦ PUT/POST ◦ DELETE ◦ Basic Authentication ◦ API key ◦ File Upload ( -F ) ◦ Insecure (-k, --insure) ◦ Config ◦ verbose
  • 7.
    Replicating browser requestswith cURL ◦ Copy as PowerShell◦ Copy as cURL
  • 8.
    Commands CURL curl -X GET"https://httpbin.org/image" -H "accept:image/webp" --output c:softwareswebp.webp curl -X GET "https://httpbin.org/image/png" -H "accept:image/png" --output c:softwarespng.png curl -s -w "%{http_code}" -X GET "https://httpbin.org/image" -H "accept:image/webp" --output c:softwareswebp.webp curl -I -X GET "https://httpbin.org/basic-auth/system/manager" -H "accept: application/json" curl -u system:manager -X GET "https://httpbin.org/basic-auth/system/manager" -H "accept: application/json" curl https://brianiswu-cat-facts-v1.p.rapidapi.com/facts -w "%{http_code}" curl -H "x-rapidapi-key:1475db38bamsh43c4c98a9ca0578p115c39jsn333977ab7597" https://brianiswu-cat-facts-v1.p.rapidapi.com/facts curl -H "x-rapidapi-key:1475db38bamsh43c4c98a9ca0578p115c39jsn333977ab7597" https://brianiswu-cat-facts-v1.p.rapidapi.com/facts --output c:softwaresoutput.json curl -v -insecure https://expired.badssl.com/
  • 9.
    Commands CURL + Elasticsearch curl-X POST http://localhost:9200/default_umc/_doc -H "content-type:application/json" --data '{"user":"anki","country":"india","city":"chennai"}' curl -X POST http://localhost:9200/default_umc/_search -H "content-type:application/json" --data '{"query":{"term":{"user":"anki"}}}' curl -X DELETE http://localhost:9200/default_umc/
  • 10.
    Commands Invoke-RestMethod invoke-restmethod -method GET-Uri https://httpbin.org/image -outfile c:softwareswebp.webp invoke-restmethod -method GET -Uri https://httpbin.org/image -header @{"accept"="image/webp"} -outfile c:softwareswebp.webp $header = @{"accept"="image/webp"} invoke-restmethod -method GET -Uri https://httpbin.org/image -header $header - outfile c:softwareswebp.webp $credentials = Get-Credential Invoke-restmethod -cred $credentials -Method GET -Uri https://httpbin.org/basic- auth/system/manager -outfile c:softwaresout.json invoke-restmethod -Method GET -uri https://brianiswu-cat-facts- v1.p.rapidapi.com/facts -Header @{"x-rapidapi- key"="1475db38bamsh43c4c98a9ca0578p115c39jsn333977ab7597"}
  • 11.
    Resources ◦ https://httpbin.org/ ◦ https://expired.badssl.com/ ◦https://rapidapi.com/brianiswu/api/cat-facts ◦ https://curlbuilder.com/

Editor's Notes

  • #7 $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("X-DATE", '9/29/2014’) $headers.Add("X-SIGNATURE", '234j123l4kl23j41l23k4j’) $headers.Add("X-API-KEY", 'testuser')