从网址获取重定向的网址 [英] Get redirected URL from URL

查看:222
本文介绍了从网址获取重定向的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题很隐蔽,但基本上发生了什么,我打电话给Google Places Photo API,并使用以下网址

The title is quite cryptic but essentially whats happening is I'm calling the Google Places Photo API with the following url

https://开头maps.googleapis.com/maps/api/place/photo?key=123456789&photoreference=CnRvAAAAV_35nLjUhcQXkoVdwN2YGP58Z3trNMDCRXznXqR2_0FbxXv60ssT2JN0ryI_ZP9-371u3JycqlH5oxLy8-bo2IkbkAfWD7fjyiytcEtWmk76Cseyxj9OlDozspXy8Cu7NFphl4N1AXSnj6QadSy6fxIQvc6Kiai-6HxMphQ7WCmYpBoUwxVnwEHl5zo0EbuoWCObJYTmAuA&maxwidth=400&maxheight=400&sensor=false

(我更改了我的API密钥)

(I've changed my API key)

通过浏览器访问此链接时,会重定向到其他网址:

When accessing this link via the browser it redirect to a different url:

https://lh3.googleusercontent.com/-WjnhIv4ry4I/T6Wg4kRb4kI/AAAAAAAuqqc/t6yVdN-jcC0/s1600-w220-h151/City%2BRestaurant

我需要一种方法来获取第二个URL使用PHP。使用cURL给我一个302文档已移到这里消息。

I need a way to get that second URL using PHP. Using cURL gives me a 302 "document has been moved to here" message.

任何人都知道我可以通过PHP获得第二个URL吗?

Anyone know how I can get that second url via PHP?

推荐答案

使用curl以 curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,true);

然后,您可以使用 curl_getinfo($ ch,CURLINFO_EFFECTIVE_URL);

或者,您可以将 CURLOPT_FOLLOWLOCATION 设置为 false ,并将 CURLOPT_HEADERS 设置为 true ,然后使用简单的正则表达式。

Alternatively, you can set CURLOPT_FOLLOWLOCATION to false, and set CURLOPT_HEADERS to true, and parse the redirect location out yourself using a simple regex.

这篇关于从网址获取重定向的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆