// 使用NSURLComponents安全地构建URL
NSURLComponents *components = [[NSURLComponents alloc] initWithString:_urlStr];
NSMutableArray *queryItems = [NSMutableArray array];
// 添加现有的查询参数(如果有)
if (components.queryItems) {
[queryItems addObjectsFromArray:components.queryItems];
}
// 添加新的参数
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"token" value:[GlobalVariables sharedInstance].token]];
[queryItems addObject:[NSURLQueryItem queryItemWithName:@"language" value:lang]];
components.queryItems = queryItems;
// 获取最终的URL字符串
_urlStr = components.URL.absoluteString;
发表回复