Curl is lovely and should be in your c:\utils folder and more importantly in your PATH. I have a UTILS folder in my Dropbox and in the PATH on all my machines. Whenever I find a useful no-install utility I put it in there.

Curl is great but it's still confusing enough to me that I don't use it enough. It's slightly obscure command-line switches are keeping me from using it on a regular basis.

For HTTP work there is a better utility called HTTPie at http://httpie.org. (It has nothing to do with IE (Internet Explorer)). For Mac and Linux folks who use Python all the time, it's easy to install, you just

pip install -U httpie

For Windows folks who don't use Python it's a little harder to install, but it's worth it and I recommend you take a moment and set it up. You'll wonder how you lived without it.

Installation of HTTPIE

First, go download Python. I got the x86 version of Python 3.2.3 cause it was the latest and I didn't think I needed the x64 one.

I then added c:\python32 and c:\python32\scripts to my path. I do this by hitting WinKey+Break, then Advanced, then Environment.

There's lots more examples here https://github.com/jkbr/httpie/ and I encourage you to check it out. I'll leave you with a lovely PowerShell screenshot showing that HTTPie also does syntax highlighting at the command line!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

Hey, this looks like a great tool and a great tutorial on setting up cUrl, Python via command line. But why not set the environment path variables via the command line as well? Here's some ways to do it: http://stackoverflow.com/questions/714877/setting-windows-powershell-path-variable

Check out Fiddler's Composer tab for similar functionality. It doesn't have the cool pseudo-JSON syntax, but I find that copy-paste-modify from previous responses is quite easy and reduces errors.

John Peterson puts this technique to great use in his aspConf Intro to Web API session. Specifically, check out 40:25-43:00 where he GETs a resource, copies the JSON response, tweaks it and PUTs it, and then GETs it to show that the changes worked. Earlier in the session (32:20-34:20) he also shows tweaking the Content-Type header to toggle between XML, JSON, or whatever.

Anyway, while HTTPIE looks pretty cool, I think Fiddler's Composer demos better, will encounter lower Microsoft cultural resistance, and is nicely integrated into other Fiddler features you already know and love.

Haha, and then I just now watched your 6-minute ASP.NET Web API video and you used Fiddler's Composer to do the exact same things as John Peterson (Accept/Content-Type and reposting modified JSON), but in a more compressed "Hanselminutes" manner! Awesome! I recommend folks check it out, from 3:30 until the end.

@Josh - Yeah, I'm suffering the same issues - it looked like the "session" option might work, but no luck with forms-based authentication. Or at least I couldn't get --session to work with --form POST. If someone does know of a way, that'd be awesome....

Any suggestions on how to get this to work behind an NTLM proxy? I was able to get curl to work, by setting a proxy in the environment setting and passing my username and password. However, running the python script failed at create connection since the proxy server refused it.

You can also just, you know, use a browser to download distribute_install.py and get-pip.py :) (just dump those links into an address bar). Didn't know easy_install will install pip, though, that will save me some time in the future!

@Robert I managed to get this working behind our proxy, as detailed below. I don't whether this approach can be easily adapted to cover your particular case, but even if not it may be of some use to others.

I then downloaded the second script using curl -x [proxy ip] -k https://raw.github.com/pypa/pip/master/contrib/get-pip.py > get-pip.pyand similarly inserted the same lines above to the beginning of the unpack() method at the end of the script. Running the modified script using python get-pip.py successfully installed pip.

Finally, I provided the --proxy parameter to pip to successfully complete the install of httpie:

I've been using Chrome's Advanced Web Client with much success but I find it's lacking a good request library to organise those large numbers of sample HTTP requests what are a typical by-product of a RESTful based dev project. HTTPIE gives me much more flexibilty in this regard.

By the way, the Pip installation failed to work for me using Python 3.X (Windows 8). Not to worry as I sailed through it after a quick install of Python 2.2.7. I would recommend this well written tutorial for those who run into similar installation difficulties.

Finbar Leahy

Thursday, 29 November 2012 19:04:55 UTC

Anyone get this working through a proxy? All web request fire me a 407.

Reuben

Monday, 03 December 2012 02:25:12 UTC

Scott, I still cant get why are you using curl if you have fiddeler installed?

Frost

Monday, 17 December 2012 17:35:08 UTC

Scott,

How did you get the highlighting to work in your powershell console? When I run *http* in a PW console, I see ASCII gibberish like below:

Anyone from you tried portable version of python and httpie? Asking because my colleague wanted to use httpie and ended at last step (some error, don't remember). So I decided to install httpie on my computer and commit to svn so everybody in our team can use it without installation.

Didn't succeeded, because easy install writes full absolute paths to python script. One quick workaround is to remove the line with absolute path, but imo it is not bulletproof generaly.