I am gratefully thanks for the article Convert NSData bytes to NSString?, especially for @christo16. I was previously dependent on ASIHttpRequest just to get value from PHP server. Now using by just this line of code :
NSString *pageContents = [NSData dataWithContentsOfURL: [NSURL URLWithString:@"http://www.apple.com"]]
I can get the functionality that I wanted.
But why is sometimes that line cause pageContents to be NULL. I already change that line into this :
NSString *fullUrl = [NSString stringWithFormat:@"http://www.apple.com"];
NSURL *url = [[NSURL alloc] initWithString:fullUrl];
NSData *pageContents;
NSString *response = NULL;
while(response==NULL)
{
pageContents = [NSData dataWithContentsOfURL: [NSURL URLWithString:fullUrl]];
response = [NSString stringWithUTF8String:[pageContents bytes]];
NSLog(@"content = %@", response);
}
Is there any better way of doing this? Up until now, I have no problem. I just wonder whether there is a more elegant way of achieving the same result
Thanks