1,加載的是html字符串
UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.bounds];
//為yes的時(shí)候朱躺,表示加載的網(wǎng)頁可以縮放,為no的時(shí)候泉蝌,網(wǎng)頁不可以縮放挖函,默認(rèn)是no
web.scalesPageToFit = YES;
// 加載 html 字符串: baseURL:基準(zhǔn)的地址:相對(duì)路徑/絕對(duì)路徑
[web loadHTMLString:html baseURL:nil];
// 將瀏覽器加載在view 上
[self.view addSubview:web];
2桩了,加載的是網(wǎng)頁地址(地址含有中文)
NSString *urlString = @"http://127.0.0.1/服務(wù)器資料/1.html";
// 在 url 中,不能出現(xiàn)漢字,只能是 ASCII 嗎! 如果 url 中出現(xiàn)了 漢字等特殊符號(hào),必須使用百分號(hào)轉(zhuǎn)譯!
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet letterCharacterSet]];
NSURL *url = [NSURL URLWithString:urlString];
// 可變的網(wǎng)絡(luò)請(qǐng)求!
// NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// cachePolicy: 網(wǎng)絡(luò)緩存策略:枚舉常量
// timeoutInterval: 請(qǐng)求超時(shí)時(shí)間! 默認(rèn)情況下,最大的請(qǐng)求超時(shí)時(shí)間是 1分鐘! 在開發(fā)中,一般設(shè) 15S
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:15];
UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.frame];
[web loadRequest:request];
[self.view addSubview:web];
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
// 可變的網(wǎng)絡(luò)請(qǐng)求!
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
// 告訴服務(wù)器,客戶端的軟件環(huán)境
// [request setValue:@"iPhone" forHTTPHeaderField:@"User-Agent"]; // 直接這樣寫,會(huì)出來一些簡單的界面
// User-Agent :通過改變這個(gè)量,可以得到自己想要的一些界面!
// 通過設(shè)置這個(gè)值,可以欺騙服務(wù)器,給我們返回不同的數(shù)據(jù)!
// 現(xiàn)在,一些大公司的頁面都做成 響應(yīng)式(自動(dòng)適配PC 端 和 移動(dòng)端) 的!
[request setValue:@"iPhone AppleWebKit" forHTTPHeaderField:@"User-Agent"];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
//
NSLog(@"response:%@",response);
[data writeToFile:@"/Users/apple/Desktop/baidu.html" atomically:YES];
UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.frame];
// 瀏覽器直接加載 二進(jìn)制數(shù)據(jù)! MIMEType :文件類型 == "Content-Type" = "text/html; textEncodingName :編碼方式 baseURL:基準(zhǔn)地址
[web loadData:data MIMEType:nil textEncodingName:nil baseURL:url];
[self.view addSubview:web];
}];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者