webView发送POST请求

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    webView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:webView];
    NSString __block  *paraStr = @"";
    
    [self.rechargeData enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull obj, BOOL * _Nonnull stop) {
        
        NSString *value = [[NSString stringWithFormat:@"%@",obj] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet letterCharacterSet]];
        
        paraStr = [NSString stringWithFormat:@"%@%@=%@&",paraStr,key,value];
        
    }];
    
    paraStr = [paraStr substringToIndex:paraStr.length - 1];
    
    NSData *postData = [paraStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
    
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:postData];
    
    [webView loadRequest:request];

你可能感兴趣的:(webView发送POST请求)