【发布时间】:2011-10-24 19:18:37
【问题描述】:
我想在向服务器发送任何请求以从服务器获取数据时添加有关 iOS 和设备型号的信息。谁能帮助我如何向服务器发送一些特定信息,以便服务器应该能够理解请求来自真实的 iPhone/iPad 设备、模拟器?
【问题讨论】:
标签: iphone ios web-services http-headers security
我想在向服务器发送任何请求以从服务器获取数据时添加有关 iOS 和设备型号的信息。谁能帮助我如何向服务器发送一些特定信息,以便服务器应该能够理解请求来自真实的 iPhone/iPad 设备、模拟器?
【问题讨论】:
标签: iphone ios web-services http-headers security
使用UIDevice currentDevice 对象访问设备信息:
型号:
[UIDevice currentDevice].model;
版本:
[UIDevice currentDevice].version;
使用ASIHTTPRequest POST 向服务器发送数据。
-(void)sendDataToServer{
NSURL *url = [NSURL URLWithString:@"http://URL_TO_YOUR_SERVER"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addPostValue:[UIDevice currentDevice].model; forKey:@"model"];
[request addPostValue:[UIDevice currentDevice].version; forKey:@"version"];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
//NO error
}else{
//Deal with error
}
}
【讨论】:
如果您在 iPhone 应用程序中使用 ASIHTTPRequest 1.6.x 库与服务器连接,您可以在 ASIHTTPRequest.m 文件中获取此信息,如下所示
#if TARGET_OS_IPHONE
UIDevice *device = [UIDevice currentDevice];
deviceName = [device model];
OSName = [device systemName];
OSVersion = [device systemVersion];
#else
deviceName = @"Macintosh";
OSName = @"Mac OS X";
#endif
【讨论】: