[IOS / Object-C] - IOS HTTP 네트워크 통신
IOS ( Object-C ) 2014. 7. 16. 14:43
NSMutableData *receiveData;
- (void) sendData : (NSString *) url : (NSString *) value : (NSString *) sendType {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *post = value;
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:sendType];
[request setHTTPBody:[value dataUsingEncoding:NSUTF8StringEncoding]];
[request setCachePolicy:NSURLRequestUseProtocolCachePolicy];
[request setTimeoutInterval:15.0f];
[request setValue:@"Mozilla/4.0 (compatible;)" forHTTPHeaderField:@"User-Agent"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *connection = [NSURLConnection connectionWithRequest : request
delegate : self];
}
// Receive Start to Submit
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *) aResponse {
NSLog(@" Receive Start ");
receiveData = [[NSMutableData alloc] init];
}
// Connection Error Event
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *) error {
[self setRetryGetData];
NSLog(@" Receive Error ");
}
// Connection Receive Event
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *) data {
NSLog(@" Receiving............ ");
[receiveData appendData:data];
}
// Connection Receive Finished
- (void) connectionDidFinishLoading : (NSURLConnection *) connection {
NSLog(@" Receive Finished ");
NSLog(@" Receive Data : %@", receiveData);
}
'IOS ( Object-C )' 카테고리의 다른 글
[IOS] - IOS UIView fadeOut & fadeIn, UIView animation (0) | 2014.07.18 |
---|---|
[IOS] - IOS 외부 이미지 불러오기, URL Image (0) | 2014.07.18 |
[IOS] - IOS System Version 정보 구하기, IOS 버전 구하기 (0) | 2014.07.11 |
[IOS] - IOS UIAlertView 버튼 이벤트 (0) | 2014.07.08 |
[IOS] - IOS Method Delay, IOS setTimeOut 매서드 실행 딜레이 (0) | 2014.07.08 |