1
好的工作。我是金槍魚。 SOAP服務連接如下:如何在swift3中使用urlsession XMLParse
// < - 連接 - > ***************************** *********************************
let xml = String(format:"<?xml version='1.0' encoding='utf-8'?><soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'><soap12:Body><Giris xmlns='http://atauni.edu.tr/'><strUserName>%@</strUserName><strPassword>%@</strPassword><TC>%@</TC><Pass>%@</Pass><DeviceID>%@</DeviceID></Giris></soap12:Body></soap12:Envelope>",strusername,strpassword,tc!,password,deviceid!)
let soapMessage = xml
let msgLength = String(describing: soapMessage.characters.count)
let url = URL(string: "http://obs.atauni.edu.tr")
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
if data == nil {
print("data hata error: \(String(describing: error))")
return
}
let mutableData : Void = NSMutableData.initialize()
//print(mutableData)
var dataString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
self.mutableData.append(data!)
print("***************************")
print(dataString ?? String())
print("***************************")
}
task.resume()
//<!--Connection--> **************************************************************
我也做了如下XML解析器操作:
我的英語不好
你可以看看這個鏈接https://stackoverflow.com/questions/31083348/parsing-xml-from-url-in-swift – KarthiKeyan
@KarthiKeyan我知道,但我的實驗再也沒有發生過 –
請不要發佈代碼的截圖。 – SiHa