How do I insert a POST request into a UIWebView

前端 未结 7 1565
故里飘歌
故里飘歌 2021-02-01 08:50

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

NSString *urlAddress = @"http://example.com/";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLReq         


        
7条回答
  •  被撕碎了的回忆
    2021-02-01 09:12

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

提交回复
热议问题