views:

49

answers:

1

Hi.

Currently I've got a web app that retrieves the URL of a mp3 on an external server, but to conserve data I'd like to check first that the page my server is retrieving is actually a redirect, not the actual content (so I can grab the URL of the mp3 and NOT the actual mp3 itself.

The external PHP script requires that json data is POSTed to it, making it hard to get the client to do it themselves.

The problem is that although the external PHP script usually redirects me to a standard URL to GET from, sometimes it returns the actual mp3 itself in the body, using up my bandwidth rather than the user's.

What would be the best solution to fix this to make me not waste my bandwidth?

Thanks.

+1  A: 

The best solution would be to use the Http verb HEAD.

From RFC2616

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.

However, the question is, does the remote server support HEAD?

Darrel Miller
Given the OP's statement, "The external PHP script requires that json data is POSTed to it" (presumably, the URL itself is insufficient to identify the resources in question), and the fact that most PHP scripts I've had experience neglect proper support for HEAD, this is probably out of the question.
Frank Farmer
You are probably right. It is a shame that HTTP is so rarely used as it was intended. It solves so many problems when done right.
Darrel Miller