UIWebView 使用


// 1. 确定要访问的资源——URL
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];

// 2. 建立网络请求
// 该请求的含义是:向服务器[请求][资源URL]
NSURLRequest *request = [NSURLRequest requestWithURL:url];

// 3. UIWebView加载网络请求
[self.webView loadRequest:request];


// 在URL中,如果包含中文字符串,需要将字符串转换为带百分号的格式
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];


// 加载Bundle里的文件
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"关于.txt" withExtension:nil];  
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];  
[self.webView loadRequest:request];


NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"iOS 7 Programming Cookbook.pdf" withExtension:nil];
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
// 服务器的响应对象,服务器接收到请求返回给客户端的
NSURLResponse *respnose = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&respnose error:NULL];
NSLog(@"%@", respnose.MIMEType);

// 在iOS开发中,如果不是特殊要求,所有的文本编码都是用UTF8
[self.webView loadData:data MIMEType:respnose.MIMEType textEncodingName:@"UTF8" baseURL:nil];


- (NSString *)mimeType:(NSURL *)url
{
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    // 服务器的响应对象,服务器接收到请求返回给客户端的
    NSURLResponse *respnose = nil;
    
    // 发送请求给服务器:url(http://服务器地址/资源路径)
    [NSURLConnection sendSynchronousRequest:request returningResponse:&respnose error:NULL];
    
    NSLog(@"%@", respnose.MIMEType);
    
    return respnose.MIMEType;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值