1

I need to send a XML via HTTP Post request in my program. But ParameterEncoding enum in Alamofire doesn't support XML parameter. I try to write custom parameter encoding:

Alamofire.request(.POST, "URL String", parameters: Dictionary(), encoding: .Custom({
        (convertible, params) in
            let mutableRequest = convertible.URLRequest.copy() as! NSMutableURLRequest
            mutableRequest.URL = NSURL(string: "URL String")
            mutableRequest.HTTPBody = "XML String".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
        return (mutableRequest, nil)
    })).authenticate(user: "student", password: "dj78dfGF")
    .response{ (request, response, data, error) in
                        let xml = SWXMLHash.parse(data!)
                        print(xml)
             }

However, it doesn't work. The result seems like the XML hasn't been sent. The URL is:

http://openapi.aurin.org.au/csw?service=CSW&request=GetRecords&typeNames=csw:Record

and the XML is:

<?xml version="1.0" encoding="UTF-8"?>
<csw:GetRecords
    service="CSW"
    version="2.0.2"
    resultType="results"
    outputSchema="http://www.opengis.net/cat/csw/2.0.2"
    xmlns:ogc="http://www.opengis.net/ogc"
    xmlns:csw="http://www.opengis.net/cat/csw/2.0.2"
    xmlns:gml="http://www.opengis.net/gml">
    <csw:Query typeNames="csw:Record">
        <csw:ElementSetName>full</csw:ElementSetName>
        <csw:Constraint version="1.1.0">
            <ogc:Filter>
                <ogc:PropertyIsLike matchCase="false" wildCard="%" singleChar="_" escapeChar="\">
                    <ogc:PropertyName>dc:subject</ogc:PropertyName>
                    <ogc:Literal>Employment</ogc:Literal>
                </ogc:PropertyIsLike>
            </ogc:Filter>
        </csw:Constraint>
    </csw:Query>
</csw:GetRecords>

Does anyone know how to send XML through HTTP? Thanks very much!

  • Possible duplicate of [How to send a request with alamofire with xml Body](http://stackoverflow.com/questions/40385992/how-to-send-a-request-with-alamofire-with-xml-body) – Lars Blumberg Dec 31 '16 at 20:59

0 Answers0