Swift: URLSession or URLRequest adds extra headers. How to omit them?

538 views Asked by At

I have set up a local express app to monitor requests made by my iOS app and found it odd that when printing the headers, one entry is

'accept-language': 'en-US,de;q=0.9'

because I did not set any specific headers at all. I tried to set nil for that header like

var request = URLRequest(url: URL(string: "http://localhost:3000/iosnativereq")!)
request.setValue(nil, forHTTPHeaderField: "Accept-Language") //also tried lower case

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    print(data, response, error)
}

task.resume()

however the requests my server gets still include the field. I would prefer having control over what headers to be sent, how can I make iOS not add these headers (or at least be able to remove them before actually performing the task)

0

There are 0 answers