gpt4 book ai didi

iphone - CFNetwork 错误 : The connection failed due to a malformed URL

转载 作者:行者123 更新时间:2023-11-29 11:08:57 24 4
gpt4 key购买 nike

在运行 iphone 应用程序时,我多次遇到以下错误

The connection failed due to a malformed URL

CFNetwork Error Codes Reference,我得到了这个错误由​​CFNetwork触发的信息

  • 何时以及为何触发此错误?
  • 如何摆脱这个错误?

最佳答案

NSURLConnection 有一个 canHandleRequest 方法,无论 url 是否有效,它都会返回一个 bool 值,例如

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;
}

关于iphone - CFNetwork 错误 : The connection failed due to a malformed URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12383602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com