WKWebView POST请求

时间:2016-05-23 11:20:35

标签: ios objective-c wkwebview

我想通过在URL中传递一些参数作为帖子请求来打开带有WKWebView的网址。但我无法做到。请帮忙。

2 个答案:

答案 0 :(得分:0)

var request = new NSMutableUrlRequest(new NSUrl(new NSString(paymentwebview.url))); //Your Url
request.HttpMethod = "POST";
request.Body = NSData.FromString(paymentwebview.data); //Data for POST
request["Content-Length"] = request.Body.Length.ToString();
request["Content-Type"] = "application/x-www-form-urlencoded charset=utf-8";
LoadRequest(request);

答案 1 :(得分:-2)

有类似的问题。对我有用的是将参数作为cookie传递。

代码示例:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod: @"POST"];
NSString *params = @"param1=value1;param2=value2;";
[request addValue:params forHTTPHeaderField:@"Cookie"];
[self.webView loadRequest:request];

希望它有所帮助!