iphone - 向服务器发送请求时如何添加设备信息?

标签 iphone ios web-services http-headers security

我想在向服务器发送任何请求以从服务器获取数据的同时添加有关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/

相关文章:

c# - 如何在同一个网站调用一个webservice?

java - HttpClient 表单 URL 包含无值参数

java - 在android中执行http不起作用

iphone - 将 SQL 行加载到索引的 UITableView

ios - iOS 中的调整大小问题

iphone - 使用 UIProgressView 倒计时期间的事件处理

iphone - 如何用图像填充组 TableView 单元格

iOS - Crashlytics 缺少 dSYM 来处理崩溃

iphone - View 禁用用户交互但 subview 启用(UIButtons)

ios - 在 UIKit 中发生内存泄漏?