Version 2020

Pass custom HTTP headers in iOS

Library Mobile SDK for iOS APIs allow you to add custom HTTP headers to each request. Custom request headers are useful for adding additional information in requests made by the Library Mobile client. One example would be adding special authentication information, such as authentication tokens you get from another authentication server, to the headers of HTTP requests. These requests are sent to the MicroStrategy Library sever.

Retrieve the SDKEnvSettings util class via MSIGeneric to access the dictionary that stores custom HTTP headers.

ReturnType

Method and Description

+(SDKEnvSettings*)

getSDKEnvSettings

This method returns the SDKEnvSettings singleton.

The following methods are exposed via the SDKEnvSettings class related with customized HTTP headers.

ReturnType

Method and Description

-(NSArray *)

getHTTPHeaderFields

This method returns all customized network header keys.

-(NSString *)

valueForHTTPHeaderField:(NSString* )field

@param field The string of the customized HTTP header key.

Provide a specific customized network header and return the value.

-(void)

removeHTTPHeaderField:(NSString* )field

@param field The string of the customized HTTP header.

Provide a specific customized network header and remove the corresponding item.

-(void)

setValue:(NSString * )value forHTTPHeaderField:(NSString * )field

@param field The string of the customized HTTP header key.

@param value Value for the customized HTTP header key you want to set.

Use this method to insert one item in customized header dictionary.

-(void)

clearHTTPHeaderFields

Use this method to clear all customized headers.

Example for passing custom HTTP headers

Use the SDKEnvSettings singleton anywhere you want to store or update custom HTTP headers in your project.

MSIGeneric.getSDKEnvSettings()?.setValue("testValue", forHTTPHeaderField: "testKey")

You can add an extra HTTP header just after a successful login in a custom login delegate. See Customize the Login process for iOS to create a custom login delegate and register it.