从网址获取重定向的网址 [英] Get redirected URL from URL
问题描述
标题很隐蔽,但基本上发生了什么,我打电话给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
(我更改了我的API密钥)
(I've changed my API key)
通过浏览器访问此链接时,会重定向到其他网址:
When accessing this link via the browser it redirect to a different url:
我需要一种方法来获取第二个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屋!