mardi 18 décembre 2018

Swift - Passing a parameter to a web service

I've come to a brick wall with this.Can anyone help? I have a web service that requires a parameter called FilteredString which has to be passed to a web service called GetProjectRegisterFiltered. I've tried a number of variations but I still get no results back. The web service is identical to another that works, I've just added a parameter to it.

    func GetFilteredRecords(){
    let is_SoapMessage: String = "<?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></soap:Body></soap:Envelope>"
    let URL: String = "http://192.168.1.208:8080/Service.asmx"
    let WebRequ = NSMutableURLRequest(url: NSURL(string: URL)! as URL)
    WebRequ.httpMethod = "POST"
    WebRequ.httpBody = is_SoapMessage.data(using: String.Encoding.utf8)
    WebRequ.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
    WebRequ.addValue(String(is_SoapMessage), forHTTPHeaderField: "Content-Length")
    WebRequ.addValue("myServices/GetProjectRegisterFiltered", forHTTPHeaderField: "SOAPAction")

    var Str: String = ""
    let task = session.dataTask(with: WebRequ as URLRequest, completionHandler: {data, response, error -> Void in
        let strData = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
        Str = String(strData!) as String
        print(strData!)
        Str = Str.replacingOccurrences(of: "&lt;", with: "<")
        Str = Str.replacingOccurrences(of: "&gt;", with: ">")
        Str = Str.replacingOccurrences(of: "&amp;", with: "&")
        let data2 = Data(Str.utf8)
        self.ReadPRData(Data: data2)

        if error != nil
        {
            print("Error: " + error.debugDescription)
        }
    })
    task.resume()
}




Aucun commentaire:

Enregistrer un commentaire