I’m needing some help on how to retrieve the full URL from a short one.
For example: http://tinysong.com/HJ9h
If you click that link it will open a grooveshark url. How can i retrieve the original grooveshark url?
Thank you
I’m needing some help on how to retrieve the full URL from a short
Share
Short URLs work by HTTP redirection. You can set up an
NSURLConnectionwith a request with the short URL and set a delegate. In the delegate, implement the method:If
responseis non-nil, it’s a redirect. You can examine the response. You can check if it’s actually an instance ofNSHTTPURLResponseusing-isKindOfClass:and then get additional data from it.Also, you can examine the new
requestthatNSURLConnectionproposes. ItsURLproperty will be the new URL to which the server redirected your connection request.If you were redirected and you have reason to believe that you won’t be redirected further and that’s all you were interested in, you can cancel the connection request by invoking
-cancelon the connection object.Update. Here’s some sample code:
Produces this output: