-(void)loadRequest:(NSString *)jsonString{
receivedData = [[NSMutableData alloc]init];
urlString = [[NSString alloc]initWithString:[NSString stringWithFormat:kURL]];
urlRequest=[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
requestInformation =[[NSMutableURLRequest alloc]initWithURL:urlRequest cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
[requestInformation setValue:khttpValue forHTTPHeaderField:kContentType];
[requestInformation setValue:@"value1" forHTTPHeaderField:@"key1"];
[requestInformation setHTTPMethod:kPost];
jsonData= [[NSString stringWithFormat:@"json=%@",jsonString] dataUsingEncoding:NSUTF8StringEncoding];
[requestInformation setHTTPBody:jsonData];
connection = [[NSURLConnection alloc] initWithRequest:requestInformation delegate:self];
[connection start];
if(connection){
NSLog(@"Connection succesfull");
}
else{
NSLog(@"There is a error in connection");
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(onFailedToUpload) userInfo:nil repeats:NO];
}
}
how to check if the else part is executed. I give incorrect URL , didfailwitherror method is called but the else part is not executed.
As far as I know, the
connectionobject is always created. Even of your url is wrong. Any errors whatsoever comes to the delegatedidFailWithErrormethod. You probably need to examine the error & proceed appropriately. Ex. In case it is a timeout you might want to retry indidFailWithErrordelegate. For other error types handle differently.If you want to handle broken or bad urls before passing it to
NSURLConnectionthen you need to do that yourself.Here are the delegates which are of use to you when using
NSURLConnection–