Wednesday, March 22, 2023
HomeiOS Developmentcordova - iOS normal http calls not passing particular headers

cordova – iOS normal http calls not passing particular headers

It isn’t attainable to pressure iOS so as to add customized headers like Origin and X-Requested-With to plain HTTP requests made by a tag, because the browser controls the era of those requests.

Nonetheless, you possibly can work round this limitation by proxying your picture requests by your API server. This entails modifying your tags to level to a URL in your API server that fetches the picture from the supply and provides the mandatory headers earlier than returning the response.

Here is an instance of how one can implement this in Swift utilizing URLSession:

let yourURL : String = "Your Url Goes Right here"
guard let url = URL(string: yourURL ) else { return }

var request = URLRequest(url: url)
request.addValue("my-origin-header-value", forHTTPHeaderField: "Origin")
request.addValue("my-requested-with-header-value", forHTTPHeaderField: "X-Requested-With")

let process = URLSession.shared.dataTask(with: request) { (information, response, error) in
    // Deal with the response


On this instance, I am making a customized URLRequest object with the mandatory headers added after which utilizing URLSession to fetch the picture information. You possibly can modify this code to fit your particular necessities and combine it along with your current codebase.

Remember the fact that this workaround has some drawbacks, reminiscent of elevated server load and potential caching points, so it must be used judiciously.



Please enter your comment!
Please enter your name here

three + 12 =

Most Popular

Recent Comments