问题
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