0

I am getting requests of a service (Beats Service to be specific) where I don't want to expose my client_id. I was able to hide it for everything except for a static image that can be retrieved using a client_id. So, here is the request:

https://partner.api.beatsmusic.com/v1/api/tracks/tr58141709/images/default?client_id=XXXXXXX

when accessing this request, the url redirects to a static image. How can I retrieve the redirected URL without loading the content to my server (I just don't want to do it. It might be a very small overhead since the artwork size is small but I don't want to have it)?

I am using Guzzle as the Http Client for PHP but that is not my main concern because if I understand how this thing works without loading the content, I will be able to enforce what I want to Guzzle.

Damjan Pavlica
  • 31,277
  • 10
  • 71
  • 76
Gasim
  • 7,615
  • 14
  • 64
  • 131
  • 1
    possible duplicate of [How to get final URL after following HTTP redirections in pure PHP?](http://stackoverflow.com/questions/3799134/how-to-get-final-url-after-following-http-redirections-in-pure-php) – RandomSeed Jan 03 '15 at 21:55
  • that url gives me `403 Forbidden` so I can't test against it. – Jasen Jan 03 '15 at 22:59

1 Answers1

1

using curl:

$url = 'https://partner.api.beatsmusic.com/v1/api/tracks/tr58141709/images/default?client_id=XXXXXXX';
$ch = curl_init($url);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

// check if we've received a redirect in the Location header
if (array_key_exists('redirect_url', $info)) {
        // do something with the Location header value
        echo $info['redirect_url'];
}
Hans Z.
  • 50,496
  • 12
  • 102
  • 115
  • that still fetches the content, you need to make a 'HEAD' request instead of a 'GET' request. – Jasen Jan 03 '15 at 22:07
  • 2
    I believe that the poster is worried about loading the content from the URL that is redirected to but moreover, a redirect in general (and this specific one for sure) does not return any content anyhow (since it would not be displayed anyway). – Hans Z. Jan 03 '15 at 22:10
  • on top of that, using HEAD against his URL produces `< HTTP/1.1 405 Method Not Allowed < Allow: GET` – Hans Z. Jan 03 '15 at 22:19
  • you need to provide a valid client id (see returned html content! ;-)) – Hans Z. Jan 03 '15 at 22:59
  • Here is a client_id: *uu23r7kzmkref56e7nga4ejf*. I will delete it after this post. So I am going to apologize to the future readers :) – Gasim Jan 03 '15 at 23:06