ASIHTTPRequest
은 사용되지 않으므로 NSURLSession
기반 서버 통신을 사용하도록 코드를 마이 그 레이션하고 있습니다. 현재 추가 사용자 정보를 보내려면 NSDictionary
"userInfo" 속성을 ASIHTTPRequest
(으)로 사용하고 있습니다. "userInfo"의 설명은 ASIHTTPRequest
설명서에서 "요청과 관련된 사용자 지정 사용자 정보 (서버로 보내지 않음)"입니다. 요청이 처리 된 후 요청 객체에서 "userInfo" 개체를 다시 가져와 그에 따라 조치를 취합니다. 내 ASIHTTPRequest
코드 예제는요청에 따라 사용자 정보 추가
요청 : 나는이 작업을 수행 할 수있는 방법
내가 NSURLSession를 통해 동일한 기능을 달성 할ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:@"http://www.google.com"];
[request setDelegate:self];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"requestCount"];
[request setUserInfo:userInfo];
?
NSURLSession 코드 예제 :
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: self.queue];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setTimeoutInterval:timeOutSeconds];
NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
}
}
}];
[dataTask resume];
합니다. – user2179059