1
votes

I'm sending a post request to a rest api to authenticate:

let url = URL(string: "http://192.168.0.103:8080/api/session")!
    var request = URLRequest(url: url)
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    request.httpMethod = "POST"
    request.httpBody = jsonData
    URLSession.shared.dataTask(with: request) {
        data, response, error in
        guard let data = data, error == nil else {
        [...]
        print(responseJSON)
    }.resume()

After that the HTTPCookieStorage contains a cookie that looks like that:

<NSHTTPCookie
    version:1
    name:TEST
    value:16268645362559017
    expiresDate:'2021-07-21 23:59:59 +0000'
    created:'2021-07-21 10:48:56 +0000'
    sessionOnly:FALSE
    domain:192.168.0.103
    partition:none
    sameSite:none
    path:/api
    isSecure:FALSE
 path:"/api" isSecure:FALSE>

Now if I send another request to the the same api to validate the cookie, the API receives the request but without the cookie.

When sending a request from a JavaScript page or Postman, everything works.

Any idea what I need to do to set the cookie to further requests?

1

1 Answers