Commit c904c4f4 cgx

完善请求头

1 个父辈 4a451cba
......@@ -43,6 +43,10 @@ NS_ASSUME_NONNULL_BEGIN
/// @param width width
/// @param attributes attributes
- (NSArray *)getLinesArrayOfStringWidth:(CGFloat)width attributes:(NSDictionary *)attributes;
/// 字典转json字符串并且转码
/// @param dict dict
+ (NSString *)convertToJsonStr:(NSDictionary *)dict;
@end
NS_ASSUME_NONNULL_END
......@@ -91,4 +91,30 @@
return (NSArray *)linesArray;
}
+ (NSString *)convertToJsonStr:(NSDictionary *)dict {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = @"";
if (!jsonData) {
NSLog(@"%@",error);
} else {
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
NSRange range = {0,jsonString.length};
[mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
NSRange range2 = {0,mutStr.length};
[mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range2];
NSString *jsonStr = [mutStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
return jsonStr.copy;
}
@end
......@@ -57,14 +57,16 @@ NSString * const NetworkUnableError = @"网络不给力,请检查您的网络
// 请求头自定义字段sid
[request addValue:[LoginUtils getSid] forHTTPHeaderField:@"sid"];
// 基础参数
NSMutableDictionary *appInfos = [NSMutableDictionary dictionary];
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
[request addValue:infoDictionary[@"CFBundleDisplayName"] forHTTPHeaderField:@"appName"];
[request addValue:@"AppStore" forHTTPHeaderField:@"promoterId"];
[request addValue:infoDictionary[@"CFBundleShortVersionString"] forHTTPHeaderField:@"version"];
[request addValue:[UIDevice currentDevice].systemVersion forHTTPHeaderField:@"versionCode"];
[request addValue:[UIDevice currentDevice].systemName forHTTPHeaderField:@"os"];
[request addValue:[[NSBundle mainBundle] bundleIdentifier] forHTTPHeaderField:@"packageName"];
[appInfos setValue:infoDictionary[@"CFBundleDisplayName"] forKey:@"appName"];
[appInfos setValue:@"AppStore" forKey:@"promoterId"];
[appInfos setValue:infoDictionary[@"CFBundleShortVersionString"] forKey:@"version"];
[appInfos setValue:[UIDevice currentDevice].systemVersion forKey:@"versionCode"];
[appInfos setValue:[UIDevice currentDevice].systemName forKey:@"os"];
[appInfos setValue:[[NSBundle mainBundle] bundleIdentifier] forKey:@"packageName"];
[request addValue:[NSString convertToJsonStr:appInfos] forHTTPHeaderField:@"appversion"];
NSURLSessionDataTask *dataTask = [[DSNetworkTool sharedManager] dataTaskWithRequest:request uploadProgress:nil downloadProgress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!