使用cURL获取重定向URL

URL redirects can be glorious or annoying depending on which side of them you are on and which side you want to be on.  Redirects are helpful for vanity URLs (useful in advertising) but sometimes they're annoying in that they could potentially break your code if you encounter a redirect you weren't anticipating.

URL重定向可能是光荣的还是令人讨厌的,具体取决于您位于重定向的哪一侧以及您希望位于哪一侧。 重定向对有用的URL(在广告中很有用)很有帮助,但有时它们很烦人,因为如果您遇到意外的重定向,它们可能会破坏您的代码。

The useful and amazing cURL command line utility allows you to fetch an address and return its final destination URL:

有用且令人惊奇的cURL命令行实用程序允许您获取地址并返回其最终的目标URL:


# "/css" doesn't exist but WordPress tries to find the closest match
# and then redirects to it ("/css-animation-callback")

curl -Ls -w %{url_effective} -o /dev/null https://davidwalsh.name/css

# Outputs: https://davidwalsh.name/css-animation-callback


The url_effective variable is what we're after.  The L directive tells cURL to follow redirects, the s directive tells cURL to be silent (i.e. not output the page contents).  You provide the URL, cURL follows it to its endpoint -- easy!

url_effective变量是我们所追求的。 L指令告诉cURL跟随重定向, s指令告诉cURL保持沉默(即不输出页面内容)。 您提供URL,cURL跟随其到达端点-简单!

翻译自: https://davidwalsh.name/curl-redirect-url

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值