Merhabalar,
Kullanıcı girişi yapan bir web servisim mevcut string olarak username ve password alıyor . Geri dönüş değeri boolean tipinde true false olarak bunu ios swiftte nasıl alabilirim true dönmesi gerekirken sürekli false olarak alıyor.
Kodlar bu şekilde : XML de userName ve Password gönderirken mi hata yapıyorum ??
@IBOutlet weak var txtUserName : UITextField!
@IBOutlet weak var txtPassword : UITextField!
var mutableData:NSMutableData = NSMutableData.init()
var currentElementName:NSString = ""
@IBAction func actionLogin(sender : AnyObject) {
guard let userName = txtUserName.text,let password=txtPassword.text where userName != "" && password !="" else { return }
let soapMessage = "<?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><Login xmlns='
http://tempuri.org/'><Login><UserName>'\(userName)'</UserName><Password>'\(password)'</Password></Login></Login></soap:Body></soap:Envelope>"
let urlString = "web service url si"
let url = NSURL(string: urlString)
let theRequest = NSMutableURLRequest(URL: url!)
theRequest.addValue("text/xml; charset=utf-8″", forHTTPHeaderField: "Content-Type")
theRequest.addValue("/(soapMessage.characters.count)", forHTTPHeaderField: "Content-Length")
theRequest.HTTPMethod = "POST"
theRequest.HTTPBody = soapMessage.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) // or false
let connection = NSURLConnection(request: theRequest, delegate: self, startImmediately: true)
connection!.start()
}
// NSURLConnectionDelegate
// NSURL
func connection(connection: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
mutableData.length = 0;
}
func connection(connection: NSURLConnection!, didReceiveData data: NSData!) {
mutableData.appendData(data)
}
func connectionDidFinishLoading(connection: NSURLConnection!) {
let xmlParser = NSXMLParser(data: mutableData)
xmlParser.delegate = self
xmlParser.parse()
xmlParser.shouldResolveExternalEntities = true
}
// NSXMLParserDelegate
func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
currentElementName = elementName
}
func parser(parser: NSXMLParser,foundCharacters string: String) {
NSLog("Return : \n", string)
}
}