I have a UIWebView
that downloads files (PDF, Word, Excel) from a web server requiring authentication. To do this I have handled the authentication and populated a NSMutableData
Object as per the Apple recommendations.
When loading the data into the UIWebView
I don't want to hardcode the Mime Type, any ideas on how to avoid this?
[_webView loadData:data MimeType: @"application/msword" textEncodingName: @"UTF-8" baseURL:[NSURL URLWithString: @""]];
Tried the below but always get "text/html" returned:
- (void)connection:(NSURLConnection *)connection didRecieveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSString *mimeType = [httpResponse MIMEType];
NSLog(@"MIMETYPE: %@",mimeType);
}
Response headers are here:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 50176
Content-Type: application/msword
Expires: -1
Server: Microsoft-IIS/7.5
Content-Disposition: attachment; filename=test.doc
X-AspNet-Version: 4.0.30319
Persistent-Auth: true
X-Powered-By: ASP.NET
EDIT: Something odd is going is happening with the headers.
The headers I originally posted were verified in Chrome and Fiddler2 but the NSURLConnection is actually receiving:
"Content-Type" = "text/html;charset=us-ascii,application/msword";
"Content-Length" = "341, 79360";
The below snippet was used to confirm this:
- (void)connection:(NSURLConnection *)connection didRecieveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
if ([response respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog([dictionary description]);
}
}
Any idea why it's receiving this invalid header, I'm stumped?