How to Use curl to Print the Location Header in a Response?

18 Replies, 737 Views

Hey folks!

So, I was messing around with curl and wanted to figure out how to *curl print location header* from a response. Took me a bit to get it right, but here's what worked for me:

```bash
curl -s -o /dev/null -w "%{redirect_url}" http://example.com
```

Basically, the `-s` silences the progress stuff, `-o /dev/null` dumps the body (don’t need it), and `-w` lets you format the output to grab just the redirect URL.

If you’re dealing with a 3xx redirect, this should spit out the location header. Super handy for scripting or just checking where a URL’s headed.

Anyone got a cleaner way to *curl print location header*? Or maybe some edge cases I’m missing? Lemme know!

Cheers! 🍻

Messages In This Thread
How to Use curl to Print the Location Header in a Response? - by - 18-06-2024, 06:53 PM



Users browsing this thread: 1 Guest(s)