I have a page that displays one string on a blank page. I need to retrieve that string. How would I do it if I wanted to do it both, synchronously and asynchronously? (I would appreciate if someone gave me the method names for both synch and asynch).
Thank you,
Have a look at the NSURLConnection reference. The methods you want are there. Also, read the URL Loading guide, it has some code examples for both synchronous and asynchronous loading.
The body data of the repsonse will be the string you want. You’ll need to be a bit careful about which encoding was used by the web site. If not specified in the response at all, it will be ISO-8859-1, otherwise it will probably be specified in the Content-Type header of the response. You then need to convert the data to an NSString with initWithData:encoding:
NB if you are not on the main thread, you can use NSStering’s stringWithContentsOfURL:usedEncoding:error:. You shouldn’t use this on the main thread because it is a synchronous method.