代碼
NSString *strUrl=[textField text];
NSString *urlString=[NSString stringWithFormat:strUrl];
NSURL *url=[NSURL URLWithString:urlString];
NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData=[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
NSString *dataStr =[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
dataStr = [dataStr substringToIndex:[dataStr length] - 16];
dataStr = [dataStr stringByAppendingString:@"
hello world navy did it
"];
NSLog(@"%@",dataStr);
const char *cString = [dataStr UTF8String];
NSData *myData= [[NSData alloc]initWithBytes:cString length:strlen(cString)+1];
[self.myWebView loadData:myData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:url];
這個代碼我是在UICatalog中WebViewController中添加的,有人要這功能,小生就乘機 學習了下,嫌麻煩,直接用的UICatalog代碼.見諒.
此代碼功能在於:在你訪問的網頁左下角加了hello world navy did it.幾個字.
不希望做流氓功能.一切以用戶為主.