Swift-3 Soap Web服务连接错误

时间:2016-10-06 10:44:19

标签: swift web-services soap swift3

我创建了肥皂网服务并尝试连接实际上它在更新后更新xcode之前有效,它发生了一些错误,你会在下面看到。知道我该怎么办呢!谢谢。 enter image description here

1 个答案:

答案 0 :(得分:3)

不使用ConnectionDataDelegate

尝试此操作
func servisRun(xml:String!){

    let soapMessage = xml
    let msgLength = String(describing: soapMessage?.characters.count)


    let url = URL(string: "http....")
    var request = URLRequest(url: url!)

    request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
    request.addValue(msgLength, forHTTPHeaderField: "Content-Length")
    request.httpMethod = "POST"
    request.httpBody = soapMessage?.data(using: String.Encoding.utf8, allowLossyConversion: false)

    let session = URLSession.shared

    let task =  session.dataTask(with: request) { (data, resp, error) in

        guard error == nil && data != nil else{

            print("connection error or data is nill")

            return
        }

        if resp != nil {

            self.mutableData.length = 0;

        }

        let mutableData : Void = NSMutableData.initialize()
        print(mutableData)

        let dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
        self.mutableData.append(data!)
        print(dataString)



    }
    task.resume()



    let xmlParser = XMLParser(data: mutableData as Data)
    xmlParser.delegate = self
    xmlParser.parse()
    xmlParser.shouldResolveExternalEntities = true

}