Home > Uncategorized > Resolve a url after a #302 redirect #Xamarin.MAC

Resolve a url after a #302 redirect #Xamarin.MAC

Say you have a url, like bit.ly/whatever – then you might want to know what the final url of that url leads to – I wanted to do that using Xamarin.MAC -although I assume that Xamarin.IOS would be the same.

NSUrl url = new NSUrl (strUrl);

NSUrlRequest request = new NSUrlRequest(url);
NSUrlResponse response = null;
NSError error = null;
NSUrlConnection.SendSynchronousRequest(request,out response,out error);
if (error != null)
url = response.Url;

The Objective C code that I copied this from was as follows:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:orinigalURL 
* cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0];
[request setHTTPMethod:@HEAD];
NSURLResponse *response = nil;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSURL *finalURL = response.URL;

As it turned out, the error was actually that I had to add this to my info.plist



Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: