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

2017-03-17  本文已影响1924人  DestinyFighter_

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];

上一篇 下一篇

猜你喜欢

热点阅读