Sample code for 30+ languages & platforms
Swift

SOAP Request to farmaclick.infarma.it

See more HTTP Misc Examples

Demonstrates how to make a SOAP HTTP request to the FCKLogin method of farmaclick.infarma.it.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // --------------------------------------------------------------------------------
    // Also see Chilkat's Online WSDL Code Generator
    // to generate code and SOAP Request and Response XML for each operation in a WSDL.
    // --------------------------------------------------------------------------------

    // Here is an example of an HTTP POST Request we'll be sending:

    // POST /documento.php HTTP/1.1
    // Content-Type: text/xml;charset=UTF-8
    // SOAPAction: https://conexion.facto.cl/documento.php/emitirDocumento
    // 
    // <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.farmaclick.infarma.it">
    //    <soapenv:Header/>
    //    <soapenv:Body>
    //       <api:FCKLogin soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    //          <inBean xsi:type="urn:LoginInputBean" xmlns:urn="urn:BeanService">
    //             <nomeTerminale xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</nomeTerminale>
    //             <password xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</password>
    //             <passwordSH xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</passwordSH>
    //             <userName xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</userName>
    //          </inBean>
    //       </api:FCKLogin>
    //    </soapenv:Body>
    // </soapenv:Envelope>

    // Use this online tool to generate code from sample XML: 
    // Generate Code to Create XML

    let xml = CkoXml()!
    xml.tag = "soapenv:Envelope"
    xml.addAttribute(name: "xmlns:xsi", value: "http://www.w3.org/2001/XMLSchema-instance")
    xml.addAttribute(name: "xmlns:xsd", value: "http://www.w3.org/2001/XMLSchema")
    xml.addAttribute(name: "xmlns:soapenv", value: "http://schemas.xmlsoap.org/soap/envelope/")
    xml.addAttribute(name: "xmlns:api", value: "http://api.farmaclick.infarma.it")
    xml.updateChildContent(tagPath: "soapenv:Header", value: "")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin", autoCreate: true, attrName: "soapenv:encodingStyle", attrValue: "http://schemas.xmlsoap.org/soap/encoding/")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean", autoCreate: true, attrName: "xsi:type", attrValue: "urn:LoginInputBean")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean", autoCreate: true, attrName: "xmlns:urn", attrValue: "urn:BeanService")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|nomeTerminale", autoCreate: true, attrName: "xsi:type", attrValue: "soapenc:string")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|nomeTerminale", autoCreate: true, attrName: "xmlns:soapenc", attrValue: "http://schemas.xmlsoap.org/soap/encoding/")
    xml.updateChildContent(tagPath: "soapenv:Body|api:FCKLogin|inBean|nomeTerminale", value: "?")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|password", autoCreate: true, attrName: "xsi:type", attrValue: "soapenc:string")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|password", autoCreate: true, attrName: "xmlns:soapenc", attrValue: "http://schemas.xmlsoap.org/soap/encoding/")
    xml.updateChildContent(tagPath: "soapenv:Body|api:FCKLogin|inBean|password", value: "?")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|passwordSH", autoCreate: true, attrName: "xsi:type", attrValue: "soapenc:string")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|passwordSH", autoCreate: true, attrName: "xmlns:soapenc", attrValue: "http://schemas.xmlsoap.org/soap/encoding/")
    xml.updateChildContent(tagPath: "soapenv:Body|api:FCKLogin|inBean|passwordSH", value: "?")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|userName", autoCreate: true, attrName: "xsi:type", attrValue: "soapenc:string")
    xml.updateAttrAt(tagPath: "soapenv:Body|api:FCKLogin|inBean|userName", autoCreate: true, attrName: "xmlns:soapenc", attrValue: "http://schemas.xmlsoap.org/soap/encoding/")
    xml.updateChildContent(tagPath: "soapenv:Body|api:FCKLogin|inBean|userName", value: "?")

    let http = CkoHttp()!

    // Indicate we want to allow an empty header..
    http.uncommonOptions = "AllowEmptyHeaders"
    http.setRequestHeader(name: "SoapAction", value: "")

    let resp = CkoHttpResponse()!
    success = http.httpStr(verb: "POST", url: "http://webservice.unicospa.it:8181/Service.svc/FrontEndService/Farmaclick2010001FCKLogin", bodyStr: xml.getXml(), charset: "utf-8", contentType: "text/xml", response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    // A status code = 200 indicates success.
    print("Response status code = \(resp.statusCode.intValue)")

    let xmlResp = CkoXml()!
    xmlResp.load(xmlData: resp.bodyStr)
    print("Response body text:")
    print("\(xmlResp.getXml()!)")

}