Chilkat Online Tools

Swift3 / Sunshine Conversations API / Set Cookie

Back to Collection Items

func chilkatTest() {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()!
    var success: Bool

    http.basicAuth = true
    http.login = "username"
    http.password = "password"

    var resp: CkoHttpResponse? = http.quickRequest("POST", url: "https://domain.com/")
    if http.lastMethodSuccess == false {
        print("\(http.lastErrorText!)")
        return
    }

    let sbResponseBody = CkoStringBuilder()!
    resp!.getBodySb(sbResponseBody)

    let jResp = CkoJsonObject()!
    jResp.loadSb(sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = resp!.statusCode.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(resp!.header!)")
        print("Failed.")
        resp = nil
        return
    }

    resp = nil

}

Curl Command

curl -X POST
	-u 'username:password'
https://domain.com/

Postman Collection Item JSON

{
  "name": "Set Cookie",
  "_postman_id": "1477e070-0d3e-4da0-9902-ffcdbcb4bfc0",
  "request": {
    "method": "POST",
    "header": [
    ],
    "url": "{{url}}/v2/apps/{{appId}}/attachments/cookie",
    "description": "With the media JWT retrieved, pass it in the header of the below request as it’s authorization in order to set a cookie in the user’s browser corresponding to the path within the media JWT.\nThe expiration date of this cookie will match the expiration date of the media JWT. This cookie will be needed to visualize a private attachment.\n"
  },
  "response": [
    {
      "id": "a3a2667d-c6ab-43b0-a9d1-62ecddc68667",
      "name": "Ok",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId/attachments/cookie",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId",
            "attachments",
            "cookie"
          ],
          "variable": [
            {
              "key": "appId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{}"
    }
  ]
}