Swift-将参数传递到Web服务



我和这个我一起去了砖墙。有人可以帮忙吗?我有一个Web服务,它需要一个称为FilterDstring的参数,该参数必须传递给称为GetProjectRegisterFiltered的Web服务。我尝试了许多变体,但我仍然没有得到任何结果。Web服务与另一种有效的服务相同,我刚刚在其中添加了一个参数。

    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()
}

我忘了感谢所有人的答复。我对肥皂要求的工作方式没有充分的了解。我现在做。我不知道我只需要将变量添加到SOAP请求字符串中:

is_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><GetDiaryByDay xmlns="MyWebWebsite"><Username>(Username)</Username><Password>(Password)</Password><Day>(Day)</Day><Month>(Month)</Month><Year>(Year)</Year></GetDiaryByDay></soap:Body></soap:Envelope>"

最新更新