前言:移动端网络请求参数已字典形式给到后端
无奈后端小白同学获取有问题只能我这边将参赛拼接URL,再已GET方式请求。
- (NSString *)paramsEncodeToFormString:(NSDictionary *)params{
NSMutableString *result = [NSMutableString string];
if(params&¶ms.count>0) {
NSInteger keyCount =0;
for(NSString*key in [params allKeys]) {
if(keyCount >0) {
[result appendString:@"&"];
}
NSString*parameter =params[key];
if([parameter isKindOfClass:[NSString class]]) {
parameter = [parameter stringByURLEncode];
}
[result appendFormat:@"%@=%@", key, parameter];
keyCount++;
}
}
if(result.length>0) {
NSString *result_n = [result stringByReplacingOccurrencesOfString:@" " withString:@""];
result_n = [result_n stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return result_n;
}
return @"";
}
网友评论