如果我想在 iPhone 应用中添加第三方代码(分析或广告),默认用户代理是什么?我该如何更改它?
最佳答案
更改请求 header 中的用户代理,如下所示:
NSString* userAgent = @"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5 BAVM/1.0.0";
NSURL* url = [NSURL URLWithString:@"http://www.stackoverflow.com/"];
NSMutableURLRequest* request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease];
[request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"%@",result);
获取当前用户代理/查找特定浏览器的用户代理:
http://www.useragentstring.com/
用户代理通常没有区别。
使用默认的就可以了,或者更好,不用担心。
关于iphone - iPhone 应用程序中的用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5622662/