Copy as curl
How do you get a curl command line to get a resource, just like the browser
would get it, nice and easy? Chrome, Firefox and Safari all have this feature.
You get the site shown with Firefox’s network tools. You then right-click on
the specific request you want to repeat in the “Web Developer->Network” tool
when you see the HTTP traffic, and in the menu that appears you select “Copy
as cURL”. Like this screenshot below shows. The operation then generates a
curl command line to your clipboard and you can then paste that into your
favorite shell window. This feature is available by default in all Firefox
installations.
In Safari, the “development” menu isn’t visible until you go into
preferences->Advanced and enable it. But once you’ve done that, you can select
“Show web inspector” in that development menu and get to see a new console pop
up that is similar to the development tools of Firefox and Chrome.
Select the network tab, reload the web page and then you can right click the
particular resources that you want to fetch with curl, as if you did it with
Safari..
If this is something you would like to get done more often, you probably find
using the developer tools a bit inconvenient and cumbersome to pop up just to
get the command line copied. Then
cliget is the
perfect add-on for you as it gives you a new option in the right-click menu,
so you can get a quick command line generated really quickly, like this
example when I right-click an image in Firefox:
These methods all give you a command line to reproduce their HTTP transfers,
but you will also learn they they are still often not the perfect solution to
your problems. Why? Well mostly because these tools are written to rerun the
exact same request that you copied, while you often want to rerun the same
logic but not sending an exact copy of the same cookies and file contents etc.
The copy as curl functionality is also often notoriously bad at using and
instead they provide handcrafted --data-binary
solutions including the mime
separator strings etc.