How do I insert a POST request into a UIWebView

前端 未结 7 1584
故里飘歌
故里飘歌 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:26

    Using loadHTMLString, feed a page to the UIWebView that has a hidden, pre-populated form, then make that page do a Javascript forms[0].submit() on loading.

    EDIT: First, you collect the input into variables. Then you compose HTML like this:

    NSMutableString *s = [NSMutableString stringWithCapacity:0];
    [s appendString: @""
     "
    " ""]; [s appendString: Param1Value]; //It's your variable [s appendString: @"
    "];

    Then you add it to the WebView:

    [myWebView loadHTMLString:s baseURL:nil];
    

    It will make the WebView load the form, then immediately submit it, thus executing a POST request to someplace.com (your URL will vary). The result will appear in the WebView.

    The specifics of the form are up to you...

提交回复
热议问题