인증이 필요한 웹 서버에서 파일 (PDF, Word, Excel)을 다운로드하는 UIWebView
이 있습니다. 이렇게하려면 인증을 처리하고 Apple 권장 사항에 따라 NSMutableData
개체를 채 웁니다.UIWebView 및 파일 MIME 형식
UIWebView
에 데이터를로드 할 때 Mime Type을 하드 코딩하지 않으려는 경우이를 방지하는 방법에 대한 아이디어가 있습니까?
[_webView loadData:data MimeType: @"application/msword" textEncodingName: @"UTF-8" baseURL:[NSURL URLWithString: @""]];
아래하지만 항상 얻을 시도 "text/html과는"반환
- (void)connection:(NSURLConnection *)connection didRecieveResponse:(NSURLResponse *)response {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSString *mimeType = [httpResponse MIMEType];
NSLog(@"MIMETYPE: %@",mimeType);
}
응답 헤더 현재 위치 :
편집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
: 홀수 뭔가가 일어나고있는 것입니다 헤더와 함께.
내가 원래 크롬과 Fiddler2에서 검증 된 게시하지만있는 NSURLConnection 실제로 수신 헤더 :
"의 Content-Type"= "text/html과; 문자셋 = US-ASCII, 응용 프로그램/msword는"이;
"Content-Length"= "341, 79360";- (void)connection:(NSURLConnection *)connection didRecieveResponse:(NSURLResponse *)response { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; if ([response respondsToSelector:@selector(allHeaderFields)]) { NSDictionary *dictionary = [httpResponse allHeaderFields]; NSLog([dictionary description]); } }
가이 유효하지 않은 헤더를 수신 왜 어떤 생각, 내가 난처한 상황에 빠진 해요 :
아래의 조각
은이를 확인하기 위해 사용되었다?
을 connectionDidFinishLoading에 보인다하지만이 작동하지 않습니다 :있는 NSString mimeType를 = [[HttpResponse에 allHeaderFields] objectForKey : @ "콘텐츠 유형"] stringValue ]; – ServerMonkey
그럼 리디렉션이 있어야한다고 생각합니다. ** - (NSURLRequest *) 연결의 응답을 확인하십시오. (NSURLConnection *) 연결 willSendRequest : (NSURLRequest *)는 redirectResponse : (NSURLResponse *) 응답 ** 메소드를 요청합니다. didReceiveResponse는 서버로부터 응답이있을 때만 호출되며, 다른 델리게이트 메소드가 프로그램 흐름을 담당 한 후에 호출됩니다. – CodeWeed