I was following these question and tutorials:
- fetching data with get post methods
- sending http get and post from cocoa
- nsurlconnection basics for beginners
- sending an http post request on ios
- how to hanlde multiple delegates
But I am still missing something. My delegate method
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
gets called all the time, takes a little bit time and I guess its because of internet speed, but the method
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data
never gets called. What am I missing? Please help me.
My code:
-(void)loadDataBase{
NSString *post = [NSString stringWithFormat:@"advnr=123"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://thewebsite.abc/interface.php"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
//return @"";
}
#pragma mark -
#pragma mark NSURLConnection delegates
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data {
NSLog(@"Success"); // never gets executed
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"didFinished");
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"FAILED");
}