简体   繁体   English

NSInputStream使用本地文件,而不使用从服务器拉下的文件

[英]NSInputStream working with with local file, not with file pulled down from server

Hey guys so I'm pulling down a yaml file from a web server. 大家好,所以我要从网络服务器上提取yaml文件。 My NSInputStream works great with local yaml files (using file://filename.yaml url scheme) 我的NSInputStream非常适合本地yaml文件(使用file://filename.yaml url方案)

Here's the relevant code snippet: 以下是相关的代码段:

NSInputStream * stream = [[NSInputStream alloc] initWithURL:yamlURL];

Where yaml url is something like http:// myip:8000/assets/test.yaml Opening in a browser just results in file download... yaml url类似于http:// myip:8000 / assets / test.yaml在浏览器中打开只会导致文件下载...

Any thoughts? 有什么想法吗?

Im way too late for this, but i just solved this exact problem, so here goes: 我为此太迟了,但我只是解决了这个确切的问题,所以去了:

As per the docs, 根据文档,

The NSStream class does not support connecting to a remote host on iOS.

As stupid as this sounds, initWithURL will only work for a local file. 听起来很愚蠢,initWithURL仅适用于本地文件。 But theres an easy fix... 但是有一个简单的解决方法...

Full explanation and code sample from apple can be found here: https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html#//apple_ref/doc/uid/20002277-BCIDFCDI 苹果的完整说明和代码示例可以在以下位置找到: https//developer.apple.com/library/mac/documentation/cocoa/Conceptual/Streams/Articles/NetworkStreams.html#//apple_ref/doc/uid/20002277- BCIDFCDI

Is there anything you're doing with the *stream, After you initWithURL? initWithURL之后,您对* stream进行任何操作吗?

If you are taking the content from the InputStream inited with the local file, you would need to be creating a NSOutputStream to take the InputStream and redirect it to Safari. 如果要从使用本地文件初始化的InputStream中获取内容,则需要创建一个NSOutputStream来获取InputStream并将其重定向到Safari。 So I don't think just initWithURL: call with the url will tell you much, but the call to open the http:// url in safari will try to determine the content-type and try to output the file. 因此,我不认为仅通过initWithURL:进行url调用会告诉您很多信息,但是在safari中打开http:// url的调用将尝试确定内容类型并尝试输出文件。 But I don't think safari would be able to display the contents if it was a mulit-part mime yaml file. 但是,我认为如果Safari是一个由多部分组成的哑剧yaml文件,则它不会显示内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM