Note that there are some explanatory texts on larger screens.

plurals
  1. POUIWebView and File Mime Types
    text
    copied!<p>I have a <code>UIWebView</code> that downloads files (PDF, Word, Excel) from a web server requiring authentication. To do this I have handled the authentication and populated a <code>NSMutableData</code> Object as per the Apple recommendations.</p> <p>When loading the data into the <code>UIWebView</code> I don't want to hardcode the Mime Type, any ideas on how to avoid this?</p> <pre><code>[_webView loadData:data MimeType: @"application/msword" textEncodingName: @"UTF-8" baseURL:[NSURL URLWithString: @""]]; </code></pre> <p>Tried the below but always get "text/html" returned:</p> <pre><code>- (void)connection:(NSURLConnection *)connection didRecieveResponse:(NSURLResponse *)response { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSString *mimeType = [httpResponse MIMEType]; NSLog(@"MIMETYPE: %@",mimeType); } </code></pre> <p>Response headers are here:</p> <pre><code>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 </code></pre> <p><strong>EDIT:</strong> Something odd is going is happening with the headers.</p> <p>The headers I originally posted were verified in Chrome and Fiddler2 but the NSURLConnection is actually receiving: </p> <blockquote> <p>"Content-Type" = "text/html;charset=us-ascii,application/msword"; <br> "Content-Length" = "341, 79360";</p> </blockquote> <p>The below snippet was used to confirm this:</p> <pre><code>- (void)connection:(NSURLConnection *)connection didRecieveResponse:(NSURLResponse *)response { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; if ([response respondsToSelector:@selector(allHeaderFields)]) { NSDictionary *dictionary = [httpResponse allHeaderFields]; NSLog([dictionary description]); } } </code></pre> <p>Any idea why it's receiving this invalid header, I'm stumped?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload