MATLAB: How to add an authorization header with a space in the value, to an http request

header authorization http request space value "value in an authinfo is an encoded username/password"MATLAB

For a http request, I would like to add a Authorization header like this "Authorization" : "api-key lettersAndNumbers". How can I do ? I already tested many solutions using AuthorizationField with or without AuthInfo, and using AuthInfo. . .
From the moment there is a space in the value of the AuthorizationField, Matlabs appears to want absolutely an AuthInfo object
But each time I try to build the AuthInfo, it will end up adding an equal sign or/and quotes surrounding the lettersAndNumbers part. . .
Here is all I tried (not totally all though):
authinfo = matlab.net.http.AuthInfo('api-key','api-key', 'NDZicHE3MmdybnZ3ZGdjZnh2dHF0NGptc2JnOWtnNzM=')
authinfo = matlab.net.http.AuthInfo('api-key', 'NDZicHE3MmdybnZ3ZGdjZnh2dHF0NGptc2JnOWtnNzM=')
authinfo = matlab.net.http.AuthInfo(AuthenticationScheme.Basic(),'api-key', 'NDZicHE3MmdybnZ3ZGdjZnh2dHF0NGptc2JnOWtnNzM=')
authinfo = matlab.net.http.AuthInfo(AuthenticationScheme.Digest(),'api-key', 'NDZicHE3MmdybnZ3ZGdjZnh2dHF0NGptc2JnOWtnNzM=')
af = matlab.net.http.field.AuthorizationField("Authorization", authinfo)
af = matlab.net.http.field.AuthorizationField("Authorization", string("api_key fkfkfkfkfk="))
af = matlab.net.http.field.AuthorizationField("Authorization: api_key fkfkfkfkfk=")
af = matlab.net.http.field.AuthorizationField("Authorization", '"api-key MDd6bGw0ZjR3MjI2OTA2cDZuY2dnaHIxYjJsazE4NHE="')
The last one could actually doesnt return any error but adds undesired quotes..
Has anyone tried something similar ?
Thank you for the help 🙂

Best Answer

Sorry for the delay, but yes I had found it a bit later. There is actually a way to add an arbitrary header, using this:
header = matlab.net.http.field.GenericField("Authorization", "api-key aznfkjndjnsn=");
r = matlab.net.http.RequestMessage('post', header, matlab.net.http.MessageBody(my_body));
This way it worked, it added an "Authorization" header without caring about the space.