美文网首页
iOS UIWebview get和post请求传参数给链接的

iOS UIWebview get和post请求传参数给链接的

作者: DestinyFighter_ | 来源:发表于2017-03-17 11:33 被阅读1924次

UIWebView 传参数给链接的页面有两种方式:

①. get请求: 直接在链接后面拼接参数.

url = [[ NSURL alloc] initWithString:@"http://www.*****.com/index.php?param1=a&param2=b&param3=c"];
[WebView loadRequest:[ NSURLRequest requestWithURL: url ]];

②. post请求: 这种方式更安全一些.

NSURL *url = [NSURL URLWithString: @"http://www.*****.com/index.php?param1=a"];
NSString *body = [NSString stringWithFormat: @"param2=%@&param3=%@",@"b",@"c"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[WebView loadRequest: request];

相关文章

网友评论

      本文标题: iOS UIWebview get和post请求传参数给链接的

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