ASIHTTPRequest UIWebView加载文件 [英] ASIHTTPRequest UIWebView load documents

查看:114
本文介绍了ASIHTTPRequest UIWebView加载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用AsiHttpRequest和UIWebView查看文档(pdf,doc,xls)的最佳方法是什么??我尝试了以下操作,但是UIWebView显示的是html:

What is the best way to view documents (pdf,doc,xls) using AsiHttpRequest and UIWebView??? I tried the following, but the UIWebView is displaying the html:

NSString * baseURL = @"http://xxxxxx/open-api/v1/";
NSString * itemRef = @"item/133/attachment/test.pdf";

NSString *urlString = [NSString stringWithFormat:@"%@%@", baseURL, itemRef];
NSURL *url = [NSURL URLWithString:urlString];

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

[request setUsername:@"xx"];
[request setPassword:@"xx"];

[request startSynchronous];

NSError *error = [request error];
if (!error) {
    [self.webView loadHTMLString:[request responseString] baseURL: [request url]];
}
else {
    NSLog(@"Error: %@", error );
}

设置基本身份验证和标头值需要AsiHttpRequest.谢谢!

AsiHttpRequest is required for setting Basic Authentication and Header Values... Thanks!

推荐答案

好吧,公平地说,您是在告诉它显示HTML,所以结果并不是真的出乎意料:-)

Well, to be fair, you're telling it to display HTML, so the result isn't really unexpected :-)

您需要在本地下载pdf文件:

You'd need to download the pdf file locally:

NSString *tmpLocation = // some temporary file location
[request setDownloadDestinationPath:tmpLocation]];
[request startSyncronous];

然后在UIWebView中查看它:

then view it in UIWebView:

NSURL *url = [NSURL fileURLWithPath:tmpLocation];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

这篇关于ASIHTTPRequest UIWebView加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆