I'm using Apple Document to create an app.I succeed in connection to the server, but I receive 0 bytes from the server(no response data). I take the following steps:
1) I create a view-based App and add a property 'receivedData':
In ViewController.h:
@property (nonatomic, retain) NSMutableData *receivedData;
In ViewController.m:
@synthesize receivedData;
2) ViewController.m's action 'ViewDidLoad', I add:
receivedData = [NSMutableData alloc];
3) Add a button in the View and add action for it:
// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://..."]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
When I debugging these codes, I find that receivedData returns 0 bytes. Any ideas about what goes wrong? A simple modify of my code will be appreciated.