
由于种种因素,现在国内的移动开发大都是原生和html5混合开发, 那么iOS端的UIWebView和WKWebView就启到了非常重要的作用! 而从我们原生页面跳转的web页面的时候我们往往需要像前端传递参数,今天我们要说的就是:webView怎么加载post请求并传递参数!
代码如下:
UIWebView *webView = [[UIWebView alloc] init]
NSString *bodyShare = [NSString stringWithFormat: @"hID=%@", userID]
NSMutableURLRequest * requestShare = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:self.urlStr]]
[requestShare setHTTPMethod: @"POST"]
[requestShare setHTTPBody: [bodyShare dataUsingEncoding: NSUTF8StringEncoding]]
[webView loadRequest:requestShare]
当然与之相对应的还有get请求来传递参数的,代码如下:
UIWebView *webView = [[UIWebView alloc] init]
self.urlStr = [NSString stringWithFormat:@"%@/tokenredirect?ostype=iphone&token=%@&time=%@",kServerPrefixURL,token,time]
NSURLRequest * requestShare = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:self.urlStr]]
[webView loadRequest:requestShare]
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)