Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created October 24, 2011 10:12
Show Gist options
  • Save igaiga/1308716 to your computer and use it in GitHub Desktop.
Save igaiga/1308716 to your computer and use it in GitHub Desktop.
Change UserAgent in NSMutableURLRequest
NSString *urlString = [NSString stringWithFormat:@"http://example.com/foo"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSString *userAgent = [NSString stringWithFormat:@"igaiga Browser"];
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
NSURLResponse *response;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment