Sample code for 30+ languages & platforms
Swift

Transition from Http.PostUrlEncoded to Http.HttpReq

Provides instructions for replacing deprecated PostUrlEncoded method calls with HttpReq.

Sends the following raw HTTP request:

POST /echoPost.asp HTTP/1.1
Host: www.chilkatsoft.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 50

company=example&ip=111.111.111.111&url=example.com

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let http = CkoHttp()!

    var url: String? = "https://www.chilkatsoft.com/echoPost.asp"

    let req = CkoHttpRequest()!
    req.addParam(name: "company", value: "example")
    req.addParam(name: "ip", value: "111.111.111.111")
    req.addParam(name: "url", value: "example.com")

    // ------------------------------------------------------------------------
    // The PostUrlEncoded method is deprecated:

    var responseObj: CkoHttpResponse? = http.postUrlEncoded(url: url, req: req)
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    // ...
    // ...

    responseObj = nil

    // ------------------------------------------------------------------------
    // Do the equivalent using HttpReq.
    // Your application creates a new, empty HttpResponse object which is passed 
    // in the last argument and filled upon success.

    let req2 = CkoHttpRequest()!
    req2.addParam(name: "company", value: "example")
    req2.addParam(name: "ip", value: "111.111.111.111")
    req2.addParam(name: "url", value: "example.com")

    req2.httpVerb = "POST"
    req2.contentType = "application/x-www-form-urlencoded"

    let resp = CkoHttpResponse()!
    success = http.httpReq(url: url, request: req2, response: resp)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    // Results are contained in the HTTP response object...

}