标签:style blog http color io os ar for sp
在之前的开发中遇到一个需求 需要像http head 中增加客户端的类型 和版本号,下面就说说怎么加及 需要注意的一些细节:
1 +(NSMutableURLRequest*)addHTTPRequestHeaderInfo:(NSURL*)requestUrl 2 { 3 NSMutableURLRequest *mutableRequest = [[[NSMutableURLRequest alloc]initWithURL:requestUrl]autorelease]; 4 NSDictionary *infoDict =[[NSBundle mainBundle] infoDictionary]; 5 NSString *versionNum =[infoDict stringForKey:@"CFBundleVersion"]; 6 NSString *appName =[infoDict stringForKey:@"CFBundleExecutable"]; 7 [mutableRequest addValue:appName forHTTPHeaderField:@"app-id"]; 8 [mutableRequest addValue:@"ios" forHTTPHeaderField:@"client-type"]; 9 [mutableRequest addValue:versionNum forHTTPHeaderField:@"app-version"]; 10 NSLog(@"%@", mutableRequest.allHTTPHeaderFields); 11 return mutableRequest; 12 }
需要注意的是:
forHTTPHeaderField的key 不能出现_(下划线)这样的字符 否则服务端获取不到。
标签:style blog http color io os ar for sp
原文地址:http://www.cnblogs.com/swiftAngel/p/4038438.html