Please post the whole code and not just this short excerpt.
I assume that you're reallocating a new NSMutableData
instance each time -connection:didReceiveData:
is called. You need to use a property or an iVar for that so that the data is appended to the already existing data when -connection:didReceiveData:
is called subsequent times.
- (void)startConnection
{
self.receivedData = [[NSMutableData alloc] init];
// Start connection...
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)
{
NSString *receivedString = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];
self.receivedData = nil;
NSLog(@"Response: %@", receivedString);
}