- (void)someMethodThatIsCalledTwice{
NSURLSession *session = [NSURLSession sharedSession];
NSString *noteDataString = [NSString stringWithFormat:@"album_id=%@&pic_id=%@", albumId,photoId];
NSURL *url = [NSURL URLWithString:stringUrl];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSLog(@"PARAMS: %@", noteDataString);
request.HTTPBody = [noteDataString dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"POST";
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
}];
}
这个问题是,如果我两次通过不同的 request.HTTPBody 调用此方法,则 dataTask 会从第二次调用中获取 noteDataString 第一次和第二次通话。
答案 0 :(得分:0)
将albumId
和photoId
作为参数传递给someMethodThatIsCalledTwice:
,例如
- (void) someMethodThatIsCalledTwiceForAlbumId:(NSString *)albumId photId:(NSString *)pahotId {
//do the stuff
}