美文网首页
iOS webview相关

iOS webview相关

作者: tongyuling | 来源:发表于2019-07-02 09:32 被阅读0次
    1、WebView怎么加载post|get请求并且传参数
    //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];
    
    //WebView加载url直接传值
    NSURL * url = [NSURL URLWithString:[[NSString stringWithFormat:@"拼接参数=%@",@"aaa"] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] relativeToURL:[NSURL URLWithString:string]];//path是路径
    [self.webView loadRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.f]];
    

    相关文章

      网友评论

          本文标题:iOS webview相关

          本文链接:https://www.haomeiwen.com/subject/tevacctx.html