Monday, August 17, 2015

Some curl basic examples

The command line browser curl is most useful and one example is sending cookies via the b-directive:

curl  -b "name=daniel"  http://www.site.com

To send cookies stored in a file, assemble cookies in a file and run:

curl -b some-cookie-file http://www.site.com

To view a websites HTTP-response-headers do:

curl http://www.site.com --head

If the website is using redirects curl must have the L-flag set to follow the redirect:

curl -L http://www.redirect.com

You may want to test out a website that is yet not in the DNS. Then set a custom Host : header identifying
the server name you want to reach but use the target ip address in the url:

 curl --header "Host: www.site.com" http://127.0.0.1/


Specify a chosen user-agent :

curl -A "Mozilla/4.0" http://www.site.com


Do a  POST request:



curl -d "param1=value1&param2=value2" http://hostname/resource
 
GET request with XML:
 
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource


File upload is done via:

curl --form "fileupload=@filename.txt" http://hostname/resource
 
Log in to a site and dump received headers to a file called headers:
 
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://site.com/Login
 
Use proxy:


curl -x proxy_ip:proxy_port http://www.site.com