更改用户代理并删除应用名称并默认使用iOS [英] Change User-Agent and remove App Name and defaults iOS
问题描述
我正在尝试在iOS中更改User-Agent,但是当我添加自定义User-Agent时,它会将其追加到包含我的应用名称的现有User-Agent中.
I am trying to change the User-Agent in iOS, however when I add my custom User-Agent it appends it to the existing User-Agent that contains my app name.
这是我正在使用的代码:
This is the code I am using:
NSMutableURLRequest *request = [client requestWithMethod:@"POST" path:endpoint parameters:nil];
[request addValue:@"MyUserAgent (iPhone; iOS 7.0.2; gzip)" forHTTPHeaderField:@"User-Agent"];
用户代理显示如下:
MyAppName/1.0 (iPhone; iOS 7.0.2; Scale/2.00),MyUserAgent (iPhone; iOS 7.0.2; gzip)
我已经读到,由于应用程序名称会自动添加到User-Agent中,因此这可能是不可能的,但是我看到了另一个类似的应用程序,它可以完全自定义User-Agent.
I've read that this might not be possible as the App name is automatically added to the User-Agent, however I have seen another similar app to mine that has managed to customise the User-Agent completely.
推荐答案
要覆盖默认用户代理,请使用setValue:forHTTPHeaderField:
而不是addValue:forHTTPHeaderField:
.例如:
To override the default user agent, use setValue:forHTTPHeaderField:
instead of addValue:forHTTPHeaderField:
. For example:
[request setValue:@"MyUserAgent (iPhone; iOS 7.0.2; gzip)" forHTTPHeaderField:@"User-Agent"];
这篇关于更改用户代理并删除应用名称并默认使用iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!