objective-c - NSUrlConnection 的 iOS 错误 URL

标签 objective-c ios nsurlconnection nsurl nsurlrequest

我在 NSString 中有一个名为 myUrl 的 url。当我 NSLog myUrl 时,我看到以下内容:

http://dl.dropbox.com/u/57665723%2FChocolatesRUs%2FJellies%2FUn-sugared%2Fgen%20no%20sugar.pdf

然后我尝试使用此 url 进行连接,如下所示:

NSURL* url = [ NSURL URLWithString:nextFileURL ];
NSMutableURLRequest* request =  [ [ NSMutableURLRequest alloc ] initWithURL: url ];
NSURLConnection* conn = [ [ NSURLConnection alloc ] initWithRequest: request delegate: self ];

我收到以下错误:

errorcode=-1000, error=Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x27e540 {NSUnderlyingError=0x26d800 "bad URL", NSLocalizedDescription=bad URL}

我试过用

NSString* myUrl = [myUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

但这也不起作用。

谁能看出问题所在?

最佳答案

也许您可以使用 stringByAddingPercentEscapesUsingEncoding 而不是 stringByReplacingPercentEscapesUsingEncoding 来转义您的 url。

关于objective-c - NSUrlConnection 的 iOS 错误 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12822006/

相关文章:

iphone - 如何知道设备类型

ios - 返回空的 NSURLConnection 数据

iPhone NSURLConnection : What to do with returned NSData Object? Google 文档 API

iOS:上传图片到服务器,打不开

ios - 如何跟踪转推和 Facebook 评论?

ios - CollectionView水平滚动约束问题

ios - 使用 NSURLConnection 取消文件上传

ios - NSOperationQueue 序列化 NSURLConnection 请求

ios - UITableViewCell 子类与 UIImageView 的正确重用方法

iphone - 使用 UITableView 和 paging.enabled=YES(或其他方式?)设置页面大小