I want to invoke or send request to my php webservice which it generates response in xml format, and I need to parse that data to get sound link and send it to player.
I have wrote the below code but when I debug it there is no response returned.
any suggestion?
var soapMsg = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body<getSounds xmlns=\"http://test.com/soap/tv\"><Language></Language></getSounds></soap:Body></soap:Envelope>"
let urlString: String = "http://test.com/tv/soapServices.php?wsdl"
var url: NSURL = NSURL(string: urlString)!
//var request: NSURLRequest = NSURLRequest(URL: url)
var request = NSMutableURLRequest(URL: url)
var msgLength = String(soapMsg.characters.count)
request.HTTPMethod = "POST"
request.HTTPBody = soapMsg.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.addValue(msgLength, forHTTPHeaderField: "Content-Length")
request.addValue("http://bee.myservice.com/userLogin", forHTTPHeaderField: "Action")
var connection: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)!
connection.start()
print(request)
var response: NSURLResponse?
// var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: nil) as NSData?
do{
var data = try NSURLConnection.sendSynchronousRequest(request , returningResponse: &response)
if let httpResponse = response as? NSHTTPURLResponse {
// print(<#T##items: Any...##Any#>)("error \(httpResponse.statusCode)")
print(response)
}
}
catch{
print("error")
}