sdept 1
@interface WebViewController ()<UIWebViewDelegate>
@property (nonatomic,strong)UIWebView * mywebview;
sdept2
self.mywebview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64)];
self.mywebview .delegate = self;
[self.view addSubview:self.mywebview ];
NSURL* urlRequest = [NSURL URLWithString:urlTest];
NSURLRequest * requst = [NSURLRequest requestWithURL:urlRequest];
[self.mywebview loadRequest:requst];
stept3
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *requestString = [[request URL] absoluteString];
QBLog(@"开始加载%@",requestString);
if ([requestString rangeOfString:@"payType"].location !=NSNotFound) {
// [self.mywebview stopLoading];
[self payMoney:requestString];
return NO;
}
if ([requestString rangeOfString:@"jjjjjjj"].location !=NSNotFound) {
[self orderCar:requestString];
return NO;
}
return YES;
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
QBLog(@"开始");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
QBLog(@"完成");
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
QBLog(@"失败");
NSLog(@"%@",[error localizedDescription]);
}
-(void)dealloc{
self.mywebview = nil;
}
1 url 拼参数
http://192.168.1.137:8085/train/home.html?init=1&token=2a9e1bed67166e0c9180f3d43948cd77f243a0f7&city=北京市
1.url编码
ios中http请求遇到汉字的时候,需要转化成UTF-8,用到的方法是:
NSString * encodingString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
2.url解码
请求后,返回的数据,如何显示的是这样的格式:%3A%2F%2F,此时需要我们进行UTF-8解码,用到的方法是:
NSString *str = [model.album_name stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
北京市转码之后为:%E5%8C%97%E4%BA%AC%E5%B8%82
前端开发需处理的转码函数
decodeURI(decodeURI("%E5%8C%97%E4%BA%AC%E5%B8%82"))