gpt4 book ai didi

ios - 如何在具有方法的 SOAP Web 服务中传递参数?

转载 作者:行者123 更新时间:2023-11-28 21:22:45 26 4
gpt4 key购买 nike

我从未使用过基于 SOAP 的服务,我不确定是否使用以下 SOAP 服务。

http://workforce.wifisocial.in/WebServicesMethods/EmployeesWebService.asmx?op=EmployeesLoginMethod

在此服务中,我需要使用参数传递 4 个值:用户名、密码、IP 地址和设备名称。输出为 JSON 格式。

请帮助实现预期的结果。

最佳答案

您只需要一个 HTTP post 请求并传递正确的 XML 数据并设置 HTTP header :

func soapRequest(username:String, password:String, ipAddress:String, deviceName:String){
if let url = NSURL.init(string: "http://workforce.wifisocial.in/WebServicesMethods/EmployeesWebService.asmx"){
let request = NSMutableURLRequest(URL: url)
let requestBody = "<?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><EmployeesLoginMethod xmlns=\"http://tempuri.org/\"><username>\(username)</username><password>\(password)</password><IpAddress>\(ipAddress)</IpAddress><deviceName>\(deviceName)</deviceName></EmployeesLoginMethod></soap:Body></soap:Envelope>"
request.HTTPMethod = "POST"
request.HTTPBody = requestBody.dataUsingEncoding(NSUTF8StringEncoding)
request.setValue("text/xml", forHTTPHeaderField: "Content-Type")
request.setValue("\"http://tempuri.org/EmployeesLoginMethod\"", forHTTPHeaderField: "SOAPAction")
NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) in
guard error == nil && data != nil else{
//handle error
return
}
if let responseString = String.init(data: data!, encoding: NSUTF8StringEncoding){
print("\(responseString)")
}
//..........
//Parse your XML response data
//.........
}).resume()

}

}

关于ios - 如何在具有方法的 SOAP Web 服务中传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39284313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com