Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

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

I have an iOS app that requests JSON data from my Rails 3 app, hosted on Heroku, and it works great on my device and for many other users, except one. I have one user who has told me that my app fails to retrieve the JSON data, so I had her send me some log data and the log showed the NSURLConnection delegate method didFailWithError is being called and the error description reads "bad URL". Why is this error occurring and why is it ONLY occurring on just some devices instead of all devices?

Here's my code,

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

and the log shows...

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

Thanks so much for all your wisdom!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It doesn't look like you are encoding the username. Are there spaces or other special characters in the username? Look into using the NSString method stringByAddingPercentEscapesUsingEncoding:.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...