views:

1266

answers:

1

Hi,

Is it possible to load a page through UIWebView with POST parameters? I can probably just load an embedded form with the parameters and fill them in with javascript and force a submit, but is there a cleaner and faster way?

Thanks!

+8  A: 

Create POST URLRequest and use it to fill webView

 NSURL *url = [NSURL URLWithString: @"http://your_url.com"];
    NSString *body = [NSString stringWithFormat: @"arg1=%@&arg2=%@", @"val1",@"val2"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
    [webView loadRequest: request];
oxigen
Tested it and it works, thanks!