Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert a POST request into a UIWebView

Tags:

post

iphone

For a GET request I've tried this simple method:

NSString *urlAddress = @"http://example.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[uiWebViewThingy loadRequest:request];

(Although it doesn't seem to work if the request contains high UTF-8 characters. )

I want to send a POST from the iPhone.

This also give an overview for sending POST/GET requests although what I really want to do is embed the resulting web page into UIWebView. What would be the best way to go around that?

like image 471
Gazzer Avatar asked Jan 04 '10 22:01

Gazzer


1 Answers

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];
like image 168
Dixit Patel Avatar answered Oct 04 '22 22:10

Dixit Patel