【发布时间】:2012-09-03 00:07:19
【问题描述】:
-(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];
}
}
如何检查 else 部分是否被执行。我给出的 URL 不正确,调用了 didfailwitherror 方法但没有执行 else 部分。
【问题讨论】:
-
如果您想处理错误的 URL,请检查 URL,而不是连接。见:stackoverflow.com/questions/1471201/… ... stackoverflow.com/questions/192944/…
标签: iphone objective-c ipad ios5 nsurlconnection