gpt4 book ai didi

iphone - iOS 开发 : Why is my NSURLConnection failing with a "bad URL" error for only some users?

转载 作者:技术小花猫 更新时间:2023-10-29 10:55:27 26 4
gpt4 key购买 nike

我有一个 iOS 应用程序,它从我的 Rails 3 应用程序请求 JSON 数据,托管在 Heroku 上,它在我的设备上和许多其他用户(除了一个)上运行良好。我有一个用户告诉我我的应用程序无法检索 JSON 数据,所以我让她给我发送了一些日志数据,日志显示了 NSURLConnection 委托(delegate)方法 didFailWithError正在调用,错误描述为 “错误的 URL”。为什么会发生此错误,为什么它只发生在某些设备上而不是所有设备上?

这是我的代码,

-(void)getTournamentInfoWithUsername:(NSString*)username
{
NSString *urlString = [NSString stringWithFormat:@"http://myapp-tourney.heroku.com/tournaments/next.json?username=%@", username];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];
[self setUrlConnection:[[NSURLConnection alloc] initWithRequest:request delegate:self]];
}

- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
[MyLog logError:[NSString stringWithFormat:@"%@ - %@ - %@ - %@", [error localizedDescription], [error localizedFailureReason], [error localizedRecoveryOptions], [error localizedRecoverySuggestion]]];
}

并且日志显示...

bad URL - (null) - (null) - (null)

非常感谢您的智慧!

最佳答案

您似乎没有对用户名进行编码。用户名中是否有空格或其他特殊字符?研究使用 NSString 方法 stringByAddingPercentEscapesUsingEncoding:

关于iphone - iOS 开发 : Why is my NSURLConnection failing with a "bad URL" error for only some users?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6162653/

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