STPostWebView
支持通过 POST 请求的 WKWebView 子类
STPostWebView 是支持通过 POST 请求的 WKWebView 子类。
要求
- iOS 8.0 或更高版本
- ARC
- Swift 5.0
安装
STPostWebView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'STPostWebView'
使用
在源文件中导入头文件
在需要使用库的源文件中,导入头文件
import STPostWebView
初始化 STPostWebView
STPostWebView 是 WKWebView 的子类。你可以像初始化 WKWebView 一样初始化它
STPostWebView(frame: frame, configuration: configuration)
加载 POST 请求
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)
运行示例
示例目录中有一个 pages 文件夹,包含一些网页文件。因为这些网页文件是用 PHP 编写的,你需要在电脑上配置 PHP 环境。然后使用 pages 文件夹启动服务器。
最后,在 Example 项目中设置该服务器的地址,例如
// ViewController.swift
let host = "https://:80"
作者
Suta, [email protected]