STPostWebView is a subclass of WKWebView that supports requested by POST.
- iOS 8.0 or later
- ARC
- Swift 5.0
STPostWebView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'STPostWebView'
In the source files where you need to use the library, import the header file:
import STPostWebView
STPostWebView is a subclass of WKWebView. You can initialize it like WKWebView:
STPostWebView(frame: frame, configuration: configuration)
var urlString = "http://xxxx:xxxx/xxxx"
let getParameterString = "key1=value1&key2=value2"
urlString += "?" + getParameterString
var request = URLRequest(url: URL(string: urlString)!)
request.httpMethod = "POST"
let postParameterString = "key3=value3&key4=value4"
request.httpBody = postParameterString.data(using: .utf8)
webView.load(request)
In the Example directory there is a pages folder with some web files. Because PHP is used to write these web files, you need to configure the PHP environment on your computer. Then use the pages folder to start a server.
Finally, set the host of this server in the Example project, for example:
// ViewController.swift
let host = "http://localhost:80"
Suta, [email protected]