设置 NSURL 以从网络服务器下载文件

发布于 2024-10-19 14:47:03 字数 214 浏览 2 评论 0原文

我想从网络服务器下载文件,好吧,到目前为止我知道如何使用 NSURL intiwithstring 下载它;--这个 url 是硬编码的 但现在我需要以下内容:

首先我正在从网络服务器读取文件路径: path = c:/programfiles/yy/ss/file/result.zip

但现在如何将此路径作为 url 来下载此文件。

我真的很困惑.. 先感谢您

I want to download file from webserver, ok till now i know how to download it with NSURL intiwithstring;--this url is hardcoded
but now i need following:

1st i am reading path of file from webserver :
path = c:/programfiles/yy/ss/file/result.zip

but now how to put this path as url to download this file.

i am really very much confused..
thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蝶…霜飞 2024-10-26 14:47:03

你需要有一个网址。您不能只从 Web 服务器的本地磁盘下载非托管文件。让返回本地文件路径的任何内容首先将其转换为 url 并将其与 NSURL 一起使用。

You need to have a url. You can't just download non hosted files from a web server's local disk. Have whatever is returning you that local file path convert it to a url first and use that with NSURL.

待天淡蓝洁白时 2024-10-26 14:47:03

好的,我明白了

NSURL *fileURL = [NSURL fileURLWithPath:UrlForDownload];  
//and also i want to add "https/100.11.1..1"  to url

//so i convert url to string as i want to add "https/100.11.1..1"   
NSMutableString *s = [fileURL absoluteString];  

[sArray addObject:s];   
NSMutableString *ResultURL = [[NSMutableString alloc]init];  
for (NSMutableString *s1 in sArray)   
{  
  [ResultURL appendString:@"https/100.11.1..1/servicename/folderForDownloadFile/"];  
  [ResultURL appendString:s1];  
  [ResultURL appendString:@"/filenameToBeDownloaded.extension"];  

}    
//filenameToBeDownloaded- i know filename and extension as i am getting full path but not filename   

//folderForDownloadFile- this folder is hosted on IIS   
//and following just continue with url and urlrequest

NSURL *url = [[NSURL alloc] initWithString:ResultURL];  

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringCacheData  timeoutInterval: 60.0]; 

ok, here i figure it out

NSURL *fileURL = [NSURL fileURLWithPath:UrlForDownload];  
//and also i want to add "https/100.11.1..1"  to url

//so i convert url to string as i want to add "https/100.11.1..1"   
NSMutableString *s = [fileURL absoluteString];  

[sArray addObject:s];   
NSMutableString *ResultURL = [[NSMutableString alloc]init];  
for (NSMutableString *s1 in sArray)   
{  
  [ResultURL appendString:@"https/100.11.1..1/servicename/folderForDownloadFile/"];  
  [ResultURL appendString:s1];  
  [ResultURL appendString:@"/filenameToBeDownloaded.extension"];  

}    
//filenameToBeDownloaded- i know filename and extension as i am getting full path but not filename   

//folderForDownloadFile- this folder is hosted on IIS   
//and following just continue with url and urlrequest

NSURL *url = [[NSURL alloc] initWithString:ResultURL];  

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringCacheData  timeoutInterval: 60.0]; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文