type of a custom NSURLProtocol?
I've written a custom subclass of NSURLProtocol, however it seems that whenever I use the protocol to load a request in UIWebView it assumes the data is content-type "text/html". Is there a way to specify that this content is actually something else (For instance "text/plain" or "image/png")?
内容类型实际上由NSURLResponse携带,您可以使用NSURLProtocolClient方法修改URLProtocol:didReceiveResponse:cacheStoragePolicy:例如,设置为text / plain
NSURLResponse *textResponse = [[NSURLResponse alloc] initWithURL:self.request.URL MIMEType:@"text/plain" expectedContentLength:100 textEncodingName:@"UTF-8"];
[self.client URLProtocol:self didReceiveResponse:textResponse cacheStoragePolicy:NSURLCacheStorageAllowedInMemoryOnly];
内容类型由NSMutableURLRequest携带。
[request setValue:@"image/png" forHTTPHeaderField:@"content-type"];
链接地址: http://www.djcxy.com/p/5924.html
上一篇: 自定义NSURLProtocol不在第二个webview中使用
下一篇: 自定义NSURLProtocol的类型?