Swift 2.0 soap request with Alamofire send xml parameters -


i want request web service example: http://www.holidaywebservice.com//holidayservice_v2/holidayservice2.asmx?wsdl

i need send 1 parameter "countrycode". don't know how can alamofire. , how response parse xml result.

this how did in postman, want know how same in swift. enter image description here

thanks help.

try it

  • will make post request
  • url = http://holidaywebservice.com/holidayservice_v2/holidayservice2.asmx?wsdl
  • the parameters sent encoding section
  • encoding: .custom =>
  • created mutblerequest
  • a. can take directly url or b. new url
  • the important mutablerequest.httbody, soap-message placed necessary values (type string)
  • the headers can vary according web service , api, in 1 case can have login / password / token or authorisation

  • the line --> "content-type" : or "content-length" depends on situation.

  • swxmlhash.parse(response.data!) handle response, 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 , charset accept      "accept-charset" : "utf-8",])  .responsepropertylist { response in         let xml = swxmlhash.parse(response.data!)                 print(xml)  } 

note : english not good


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -