Change User-Agent and remove App Name and defaults iOS

让人想犯罪 __ 提交于 2019-12-21 03:55:13

问题


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"];

And the User-Agent appears like this:

MyAppName/1.0 (iPhone; iOS 7.0.2; Scale/2.00),MyUserAgent (iPhone; iOS 7.0.2; gzip)

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.


回答1:


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"];


来源:https://stackoverflow.com/questions/19297596/change-user-agent-and-remove-app-name-and-defaults-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!