在做HTTP或者HTTPS 数据请求的时候,有些设备信息可以添加到http的header里面。
1、原生数据请求
NSString *strUrl=[NSString stringWithFormat:@" 你的地址"];
NSURL *url=[NSURL URLWithString:strUrl];
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];
[request setHTTPMethod:@"GET"];[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"字段对应的值1" forHTTPHeaderField:@"你头部的字段1"];
[request setValue:@"字段对应的值2" forHTTPHeaderField:@"你头部的字段2"];
mConn=[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:true];
2、使用AFNetworking2.x
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
网友评论