How can I determine the User-Agent for an iOS application's HTTP request?

限于喜欢 提交于 2019-12-25 06:31:32

问题


I have an iOS application that downloads an xml file using:

NSURL *queryURL = [NSURL URLWithString:query];
NSData *xmlData = [[NSData alloc] initWithContentsOfURL:queryURL];

The call is made to a third-party, so I'm not in control of the servers. The third party needs to know what that user-agent is (they are optimizing the feed based on the user-agent)

My question is how can I determine what my user-agent is? I don't specifically set that anywhere and didn't find anything in the documentation.


回答1:


The user-agent is undocumented and subject to change. If you want to control the user-agent header, you will need to use NSURLConnection with an NSMutableRequest. Apple's documentation has an example of how to use NSURLConnection.




回答2:


It has to do with the name of your app (bundle identifier). In the end I just wrote a quick method to call a web server I do have control of, launched the app, and then read the logs from that web server and I could see the exact user-agent information.



来源:https://stackoverflow.com/questions/7361028/how-can-i-determine-the-user-agent-for-an-ios-applications-http-request

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