Rest API request returns 303 error in app

I have this basic get request when I call it in app I receive the error below. When I run it in playgrounds I get the same error
Code Block
let url = DevAPI.BaseURL.submitted
guard let requestUrl = url else { fatalError() }
var request = URLRequest(url: requestUrl)
request.httpMethod = "GET"
let tokenString = UserDefaults.standard.string(forKey: "name") ?? ""
request.setValue(tokenString, forHTTPHeaderField: "x-access-token")
let session = URLSession.shared
session.dataTask(with: request) { (data, response, error) in
if error != nil {
  print("error :::", error)
   } else {
        print("no error", response)
    }
}.resume()
This request is never making it to the server as in the logs I don't see anything show up when its made.

Code Block 2020-12-23 12:29:37.815500-0500 Hammoq[63627:1122236] Task <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1> HTTP load failed, 5071/0 bytes (error code: 303 [4:-2205])
2020-12-23 12:29:37.817028-0500 Hammoq[63627:1122236] Task <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1> finished with error [303] Error Domain=kCFErrorDomainCFNetwork Code=303 "(null)" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>, _kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey=<CFData 0x600003820f50 [0x7fff8002e8c0]>{length = 16, capacity = 16, bytes = 0x100201bb23b852d00000000000000000}, _kCFStreamErrorCodeKey=-2205, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>"
)}
error ::: Optional(Error Domain=kCFErrorDomainCFNetwork Code=303 "(null)" UserInfo={_NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>, _kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey=<CFData 0x600003820f50 [0x7fff8002e8c0]>{length = 16, capacity = 16, bytes = 0x100201bb23b852d00000000000000000}, _kCFStreamErrorCodeKey=-2205, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <9EAC71EE-DA88-4356-A180-D843E89CC7B9>.<1>"
)})

If I use a different url from the same db I don't receive any errors. Another strange thing is that if I remove the header "x-access-token" I do not get the error and instead get response 403 which makes sense.


Replies

If I use a different url from the same db I don't receive any errors. Another strange thing is that if I remove the header "x-access-token" I do not get the error and instead get response 403 which makes sense.

This looks like you are talking to a server, load balancer, or internal network proxy that you didn't expect to after you authenticated inside a larger network. For example, the clue about receiving a 403 when you remove your access token means that your app seems to be authenticating through a larger network fine, but when you receive a 303 the internal network you are talking to does not like the redirect. To resolve this try tracing a network map and then taking logs in the last server you hit before losing your network request. A packet trace would work to give you a starting point on where to look first.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

In my case I have got this error due to Aborting a request on Charles Proxy -> Breakpoints screen. It looks that Charles in such a case is returning null response