我想在向服务器发送任何请求以从服务器获取数据的同时添加有关iOS和设备型号的信息。任何人都可以帮助我如何向服务器发送一些特定信息,以便服务器应该能够理解来自真实iPhone / iPad设备模拟器的请求吗?
最佳答案
使用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 - 向服务器发送请求时如何添加设备信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7880715/