
A curl cheat sheet - fcambus
http://daniel.haxx.se/blog/2015/09/16/a-curl-cheat-sheet
======
coderholic
Not strictly a curl hack, but you can quickly get your IP geolocation details
with curl and [http://ipinfo.io](http://ipinfo.io) (full disclosure, it's my
service):

    
    
      $ curl ipinfo.io
      {
        "ip": "208.54.39.206",
        "hostname": "mce2736d0.tmodns.net",
        "city": "Los Angeles",
        "region": "California",
        "country": "US",
        "loc": "34.0522,-118.2437",
        "org": "AS21928 T-Mobile USA, Inc.",
        "postal": "90013",
        "phone": 213
      }
      

Or just your IP

    
    
      $ curl ipinfo.io/ip
      208.54.39.206
      

Or any other field (eg. city)

    
    
      $ curl ipinfo.io/city
      Los Angeles
      

Or lookup another IP

    
    
      $ curl ipinfo.io/8.8.8.8
      {
        "ip": "8.8.8.8",
        "hostname": "google-public-dns-a.google.com",
        "city": "Mountain View",
        "region": "California",
        "country": "US",
        "loc": "37.3860,-122.0838",
        "org": "AS15169 Google Inc.",
        "postal": "94040",
        "phone": 650
      }
    

Or a specific field for that IP:

    
    
      $ curl ipinfo.io/8.8.8.8/org
      AS15169 Google Inc.

~~~
dfc
If you start a comment out with "not strictly [related to linked article]" and
hijack the discussion by plugging a website it seems like the decent thing to
do is mention that you are the developer behind said website. I think this is
even more important when you include so much <pre> text that the other
comments are pushed so far down the page.

 _Full-Disclosure: Some people still believe in it_

~~~
coderholic
Thanks for the tip. I've updated the comment to add the disclosure. Definitely
not my intention to hide it though, it's clearly listed in my profile.

------
trashcan
Slightly offtopic, but I highly recommend using httpie for command line http:

[https://github.com/jkbrzt/httpie](https://github.com/jkbrzt/httpie)

No cheatsheeet needed, the syntax is a lot friendler.

~~~
glynjackson
Found httpie sometime back. I still use curl but 80% of the time I use httpie
now.

------
wldcordeiro
While great, I stopped using it for httpie instead, it has a much simpler
interface.

~~~
sohkamyung
Maybe I'm wrong, but httpie appears to be targetting http transactions only,
while curl supports multiple protocols (ftp, etc.).

curl's syntax is also baked into various Web Browser network debuggers. Both
Chrome and Firefox's network transactions display have a "output to curl"
option to allow you to recreate the network transaction exactly.

Edit: on Firefox, the option is "Copy as curl"

~~~
wldcordeiro
That is true, curl has some additional protocol features and then of course it
being a standard part of most *nix OSes makes it easy to understand why Chrome
and Firefox both have the copy as curl option. I still use curl regularly but
for any pure http(s) stuff I use httpie because of its improved user
experience.

------
baldfat
Confessions. I know I should use curl but I never do and just use wget and
think curl is just a one year newer wget :(

curl is better tool than wget but I used wget first and never changed. I do
use aria2c more now for downloading but I know curl is a great tool I don't
use.

------
javajosh
May I suggest adding `--proxy URL` which is useful if using Charles/Fiddler to
toggle between environments.

~~~
est
I use `HTTP_PROXY=[http://xxx](http://xxx) curl xxxx` all the way. Works for
any program, without need to remember different option syntax.

~~~
teddyh
In my experience the proxy environment variable (contrary to most other
environment variables) must be _lower case_ , i.e. “http_proxy”. Therefore:

    
    
      http_proxy=http://proxy-server.example:3128/ some_command

~~~
est
You are absolutely right. I stand corrected.

------
est
curl -e "referer"

