2012-08-29 40 views

回答

7

试试这个:

NSError* e; 
NSString* str = [NSString stringWithContentsOfURL:@"http://mysite.com/files/objects.txt" encoding:NSASCIIEncoding error:&e] 
if(e != nil) { 
    //There was an error 
} 
//Everything good 
+0

很好的作品:) –

+0

@IdreesAshraf:太好了。很高兴我能帮上忙。 – Linuxios

1

注意的语法已与最近的iOS更新改变...

NSError* err; 
NSURL* url = [NSURL URLWithString:@"<your URL goes here>"]; 
NSString* str = [NSString stringWithContentsOfURL:url 
              encoding:NSASCIIStringEncoding 
               error:&err];