Why isn't -stringWithContentsOfURL returning my php echo?

My application is accessing a simple php file on my server that makes a simple echo "YES"; for testing purposes. I am trying to get the echo content into an NSString object as shown below, but my string ALWAYS returns (null). What's wrong?

NSString *theString = [NSString stringWithContentsOfURL:aURLThatEchos];
NSLog(@"Value is: %@", theString);



//Outputs: Value is: (null)

      

+2


source to share


2 answers


Make sure the url is actually valid but not a null NSURL object. Make sure the server sees the hit. You can also try using NSURLConnection, ASIHTTPRequest, or some other asynchronous method to make the request, as this will give you more error and error information.



+1


source


To make sure you know that when called, the stringWithContentsOfURL

url should not be a string, but an NSURL object, using [NSURL URLWithString:@"http://site.com"];

?



+1


source







All Articles