6

我想使用以下网页制作CocoaHTTPServer:应该有一个下载文件的链接,但源文件必须是NSData内存中的对象。

据我在示例中看到的,有一种简单的方法可以将 iPhone 上的某些文件链接到超链接。是否可以“链接” NSData

将非常感谢示例。

4

1 回答 1

7

您需要做的就是HTTPDataResponse在您的 HTTPConnection 子类中返回。

如果您想要一个示例,请查看调用的 CocoaHTTPServer 示例DynamicServer并将其替换- httpResponseForMethod: URI:MyHTTPConnection类似于以下内容的内容:

- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
{
    // Before returning you can analyze the passed path argument and select the correct data object to return...
    return [[HTTPDataResponse alloc] initWithData:placeYourDataInstanceHere];
}
于 2012-10-18T16:28:37.650 回答