I want to do a request to this web service example: http://www.holidaywebservice.com//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.
Try it
the Headers can vary from according to the web service and API, in one case can have login / password / token or only authorisation
the line --> "Content-Type" : or "Content-Length" depends on the situation.
SWXMLHash.parse(response.data!) is to handle the response, your can see more in [AlamoFire / Usage / Response Handling ] (https://github.com/Alamofire/Alamofire)
Alamofire.request(.POST, "http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl",
parameters: nil,
encoding: .Custom({
(convertible, params) in
//a.
let mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest
// or
//b.
mutableRequest.URL =NSURL(string: theUrlString)
let mutableReques02 = NSMutableURLRequest(URL: theURL!)
//
//mutableReques02.HTTPBody =....
mutableRequest.HTTPBody =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:sap-com:document:sap:rfc:functions\"><SOAP-ENV:Body>
<hs:GetHolidaysAvaible>
<hs:countrycode> UnitedStates</hs:countrycode>
</hs:GetHolidaysAvaible>
</SOAP-ENV:Body></SOAP-ENV:Envelope>".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
return (mutableRequest, nil)}),
headers:
["Username": "login", // Login API
"Password": "password" , // Password API
"AuthenticatedToken" : "35432", // Authenticated API
"Authorization": "Basic nasiouynvo8eyt829409", // Authenticated API
"Accept" : "text/xml",
"Content-Type" : "text/xml; charset=UTF-8", // Type content and charset accept
"Accept-Charset" : "UTF-8",])
.responsePropertyList { response in
let xml = SWXMLHash.parse(response.data!)
print(xml)
}
Note : My English is not very good
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With