在运行iphone应用程序时,我多次收到以下错误
The connection failed due to a malformed URL在CFNetwork Error Codes Reference,我得到了CFNetwork触发的错误信息
发布于 2012-09-12 08:34:51
NSURLConnection有一个方法canHandleRequest,它将返回一个布尔值,不管url是否有效。
NSString *strUrl = [NSString stringWithFormat:@"http://test.com/stopBoard/%i",busStopCode];
NSURL *url = [NSURL URLWithString:strUrl];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:20.0];
// a cache policy of NO must be used otherwise the previous query is used if the phone is not online
BOOL canGo = [NSURLConnection canHandleRequest:request];
if(canGo){
connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:YES];
} else {
self.errorMessage = @"\n\nurl check failed\n\n";
return NO;
}https://stackoverflow.com/questions/12383602
复制相似问题