带有Alamofire的Swift 2.0 Soap请求发送xml参数

编程入门 行业动态 更新时间:2024-10-21 17:34:09
本文介绍了带有Alamofire的Swift 2.0 Soap请求发送xml参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想对此Web服务示例进行请求:

感谢您的帮助。

解决方案

我编写了一个pod,用于将XML映射到对象,名为 XMLMapper 。 (使用与 ObjectMapper 相同的技术)

您可以使用请求子规范轻松创建SOAP请求。 p>

首先创建自己的自定义 SOAPMessage :

类HolidayServiceMessage:SOAPMessage { var countryCode:字符串? 覆盖功能映射(map:XMLMap){ super.mapping(map:map) countryCode<-map [ m:countrycode] } }

然后创建SOAPEnvelope,例如:

let soapMessage = HolidayServiceMessage(soapAction: GetHolidaysAvaible,nameSpace: holidaywebservice/HolidayService_v2) soapMessage.countryCode =美国 let soapEnvelope = SOAPEnvelope(soapMessage:soapMessage)

最后使用Alamofire发送SOAP请求:

Alamofire.request( holidaywebservice/HolidayService_v2/HolidayService2.asmx ?wsdl,方法:.post,参数:soapEnvelope.toXML(),编码:XMLEncoding.soap(withAction: holidaywebservice/HolidayService_v2#GetHolidaysAvaible))

您可以使用 XMLMappable 协议将XML响应映射到快速对象。

I want to do a request to this web service example: www.holidaywebservice//HolidayService_v2/HolidayService2.asmx?wsdl

I need to send one parameter "countryCode". I don't know how can i do that with alamofire. And how i get the response to parse the xml result.

This is how i did in postman, but i want to know how do the same in swift.

Thanks for your help.

解决方案

I wrote a pod for mapping XML to objects, called XMLMapper. (uses the same technique as the ObjectMapper)

You can use the Requests subspec to create easily SOAP requests.

First create your own custom SOAPMessage:

class HolidayServiceMessage: SOAPMessage { var countryCode: String? override func mapping(map: XMLMap) { super.mapping(map: map) countryCode <- map["m:countrycode"] } }

Then create the SOAPEnvelope like:

let soapMessage = HolidayServiceMessage(soapAction: "GetHolidaysAvaible", nameSpace: "holidaywebservice/HolidayService_v2") soapMessage.countryCode = "UnitedStates" let soapEnvelope = SOAPEnvelope(soapMessage: soapMessage)

Finaly send the SOAP request using Alamofire:

Alamofire.request("holidaywebservice/HolidayService_v2/HolidayService2.asmx?wsdl", method: .post, parameters: soapEnvelope.toXML(), encoding: XMLEncoding.soap(withAction: "holidaywebservice/HolidayService_v2#GetHolidaysAvaible"))

You can map the XML response to swift objects using XMLMappable protocol.

更多推荐

带有Alamofire的Swift 2.0 Soap请求发送xml参数

本文发布于:2023-11-26 02:56:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   Swift   Alamofire   xml   Soap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!