通过 NSURL 访问另一台电脑的文件
我可以通过 NSURL 访问我的本地文件:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://localhost/Users/user/Desktop/lucky_numbers.json"]];
但我需要访问另一台电脑的文件。 我尝试过:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://foyzulkarim:[email protected]/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
和
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://192.168.1.48/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://Foyzul-Karims-MacBook.local/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]]
但错误显示 NSURLError 域代码 -1100
如果有人知道如何执行此操作,请帮助我。
I can access to my local file through NSURL by using:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://localhost/Users/user/Desktop/lucky_numbers.json"]];
But I need to get access of a file of another PC.
I tried:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://foyzulkarim:[email protected]/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
and
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://192.168.1.48/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
and
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://Foyzul-Karims-MacBook.local/localhost/Users/foyzulkarim/Desktop/lucky_numbers.json"]];
But Error shows NSURLError domain code -1100
Please help me if anyone knows how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不那样工作。
file:
URI 方案仅支持本地文件访问,不支持远程文件访问。对于远程访问,您需要一个真正的网络协议,例如 HTTP 或 FTP,以及远程站点上的服务器。I doesn't work that way. The
file:
URI scheme only supports local file access, not remote. For remote access you need a real network protocol like HTTP or FTP and thus a server on the remote site.您可以使用以下方法通过 NSURL 访问我的本地文件:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://192.168.1.48/localhost/Volumes/foyzulkarim/Desktop/lucky_numbers.json"] ];
但是,要执行此操作,您必须首先手动连接该电脑。
You can access to my local file through NSURL by using:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"file://192.168.1.48/localhost/Volumes/foyzulkarim/Desktop/lucky_numbers.json"]];
but, to do this you have to first connect with that PC manually.