NSURL example / sample code

1012阅读 0评论2009-11-20 xw_max
分类:

// NSCocoaErrorDomain
-(void) test1_domain_error
{
    [self addLog: [NSString stringWithFormat:@"%s %d", __FUNCTION__, __LINE__]];
   
    NSError *error = nil;
    NSString *urlString = @"";
    NSURL *url = [NSURL URLWithString: urlString];
    NSString *webResponse = [NSString stringWithContentsOfURL: url encoding: NSUTF8StringEncoding error: &error];
   
    [self addLog: [NSString stringWithFormat:@"Accessing %@", urlString]];
   
    if(nil != error)
    {
        [self addLog: [NSString stringWithFormat: @"Error code = %d, %@", [error code], [error domain]]];
    }
    else
    {
        [self addLog: [NSString stringWithFormat: @"Access %@ OK, webResponse = %@", urlString, webResponse]];
    }
   
}



上一篇:sqlite + NSString UTF8注意点
下一篇:Cocoa 正则表达式 OgreKit