美文网首页
iOS WebView Post请求

iOS WebView Post请求

作者: 你的小福蝶 | 来源:发表于2019-09-26 09:10 被阅读0次

    webView请求:Post&Form

        NSString *url = @"";
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:url]];
        //[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];  //json请求
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPMethod: @"POST"];
    
        /* 1.json请求
        NSDictionary *recprotocallistDic = @{@"recprotocallist":self.recprotocallist};
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:recprotocallistDic options:NSJSONWritingPrettyPrinted error:nil];
        [request setHTTPBody:jsonData];*/
    
        //2.form请求,这里的self. recprotocallistStr是string,根据后端要求来选择
        NSString *str = [NSString stringWithFormat:@"recprotocallist=%@",self.recprotocallistStr];
        NSData *jsonData = [str dataUsingEncoding:NSUTF8StringEncoding];
        [request setHTTPBody:jsonData];
    
    
        //请求
        UIWebView *webView = [[UIWebView alloc]init];
        [webView loadRequest:request];
    

    Form2

        /*
         NSDictionary *postUrlData = recprotocallistDic;
         
         NSMutableString *htmlString = [NSMutableString string];
         [htmlString appendString: [NSString stringWithFormat:@"<html><body onload=\"document.forms[0].submit()\">""<form method=\"post\" action=\"%@\">", url]];
         [postUrlData enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSString *  _Nonnull obj, BOOL * _Nonnull stop) {
         [htmlString appendString: [NSString stringWithFormat:@"<textarea style=\"display:none\" name=\"%@\">%@ </textarea>\n", key, obj]];
         }];
         [htmlString appendString: @"</form></body></html>"];
         ESignatureVC *webVC = [[ESignatureVC alloc]init];
         [webVC.wkWebView loadHTMLString:htmlString baseURL:nil];
         [self push:webVC animation:YES andNotHiddenTabbar:true];*/
    

    相关文章

      网友评论

          本文标题:iOS WebView Post请求

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