gpt4 book ai didi

iphone - ASIHTTPRequest UIWebView加载文档

转载 作者:行者123 更新时间:2023-12-03 21:21:51 25 4
gpt4 key购买 nike

使用 AsiHttpRequest 和 UIWebView 查看文档(pdf、doc、xls)的最佳方式是什么???我尝试了以下操作,但 UIWebView 正在显示 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 );
}

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

最佳答案

好吧,公平地说,您告诉它显示 HTML,所以结果并不意外:-)

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

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

然后在UIWebView中查看:

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

关于iphone - ASIHTTPRequest UIWebView加载文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3890528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com