Alamofire Error Domain=NSURLErrorDomain Code=-999 “cancelled”

前端 未结 5 1114
既然无缘
既然无缘 2021-01-05 14:15

I already have successfully got keychain for my token and passing it to AccessTokenAdapter class shown below. http127.0.0.1:8000/api2/projects/?format=json is passed as proj

5条回答
  •  -上瘾入骨i
    2021-01-05 15:06

    Just solved. Looks like it's required to set httpmethod beforehand.

        let url = URL(string: "http://127.0.0.1:8000/api2/projects/?format=json")
        var urlRequest = URLRequest(url:url!)
        urlRequest.httpMethod = HTTPMethod.get.rawValue
        urlRequest.addValue("JWT \(self.keychain["token"]!)", forHTTPHeaderField: "Authorization")
        urlRequest.addValue("application/json", forHTTPHeaderField: "Accept")
        Alamofire.request(urlRequest)
            .responseJSON { response in
                debugPrint(response)
        }
    

提交回复
热议问题