This is because you cannot change sharedSession. Imagine that sharedSession is an iOS device sharedSession and is used by all other applications and frameworks. Does it make sense that it is not configurable correctly? The documentation says about it:
The general session uses the currently installed global NSURLCache, NSHTTPCookieStorage and NSURLCredentialStorage Objects and are based by default.
What you want to do is define a custom configuration in which you will need your own session objects with your own configuration. This is why there is a specific constructor that gives you what you need:
+ (NSURLSession *)sessionWithConfiguration:(NSURLSessionConfiguration *)configuration delegate:(id<NSURLSessionDelegate>)delegate delegateQueue:(NSOperationQueue *)queue
For brevity, you can use [NSURLSessionConfiguration defaultSessionConfiguration] to create a basic configuration, and then set additional headers there.
Naturally, you are responsible for maintaining the session, etc.
source share