仅在使用iOS 10时,iOS WKWebKit POST请求不发送数据(适用于iOS 11及更高版本)

时间:2018-11-16 13:12:54

标签: ios post wkwebview

我正在iOS中使用Webkit视图,我正在对服务器进行邮寄呼叫。请求的代码是

        let escapedString = linkString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) // Linkstring = "website/api/postRequest"

        let dic = ["refId": "600"] as [String: String]

        let jsonData = try? JSONSerialization.data(withJSONObject: dic, options: .prettyPrinted)
        let myURL = URL(string: escapedString!)
        var myRequest = URLRequest(url: myURL!)
        myRequest.httpMethod = "POST"
        myRequest.httpBody = jsonData

        myRequest.addValue("application/json", forHTTPHeaderField: "Content-Type")
        myRequest.setValue("application/json", forHTTPHeaderField: "Accept")
        webView.load(myRequest)

`

当我在iOS 11及更高版本中加载此文件时,数据作为正文参数(request.body)发送到服务器,但是当我在iOS 10设备req.body中发送相同内容时为空。

当我调试并尝试

po JSONSerialization.jsonObject(with: myRequest.httpBody!, options: .allowFragments)

我得到字典的回复[“ refId”:“ 600”]

感谢您的帮助

谢谢

0 个答案:

没有答案