The first step is to create the URL
Nsurl *url = [Nsurl urlwithstring:@ "Http://itunes.apple.com/search?term=&entity=software"];
The second step is to create a network request via a URL
Nsurlrequest *request = [[Nsurlrequest alloc]initwithurl:url Cachepolicy:nsurlrequestuseprotocolcachepolicy TIMEOUTINTERVAL:10];
Step three, connect the server
NSData *received = [nsurlconnection sendsynchronousrequest:request returningresponse:nil Error:nil];
NSString *str = [[NSString alloc]initwithdata:received encoding:nsutf8stringencoding];
NSLog (@ "%@", str); It's so simple, it's done here, and Str is the result of the request.
Note: The parameters in the second step are explained as follows:
//nsurlrequest Initialization method first parameter: Request access path, second parameter: Cache protocol, third parameter: Network request time-out (seconds)
// where the cache protocol is an enumeration type that contains:
nsurlrequestuseprotocolcachepolicy//(Basic strategy)
nsurlrequestreloadignoringlocalcachedata//(ignoring local cache)
nsurlrequestreturncachedataelseload//(First use cache, if there is no local cache, download from the original address)
nsurlrequestreturncachedatadontload//(use local cache, never download, if there is no cache locally, the request fails, this policy is used for offline operations) www.2cto.com
nsurlrequestreloadignoringlocalandremotecachedata//(ignoring any caching policies, whether local or remote, always re-downloaded from the original address)
nsurlrequestreloadrevalidatingcachedata//(does not download if the local cache is valid, and any other cases are re-downloaded from the original address)
Implementation of iOS sync GET request