0
비동기 HTTP get action을 테스트하려고합니다.비동기 HTTP 테스트 GHUnit 테스트
@interface Sender : NSObject<NSURLConnectionDataDelegate, NSURLConnectionDelegate>
{
NSMutableData *buffer;
NSString *_html
}
- (void)getHtml;
@end
@implementation Sender
- (void)getHtml
{
NSString *urlstr = @"http://www.yahoo.co.jp";
NSURL *url = [NSURL URLWithString:urlstr];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self];
if (conn) {
buffer = [NSMutableData data];
} else {
// error handling
}
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[buffer appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Succeed!! Received %d bytes of data", [buffer length]);
_html = [[NSString alloc] initWithData:buffer encoding:NSUTF8StringEncoding];
NSLog(@"%@", _html);
}
@end
나는 _html
재산을 할 필요가?
더 좋은 방법이 있다면 알려주세요. 감사합니다.