User382
User382

Reputation: 874

Xamarin iOS Authorization Header with UIWebView request

I would like to add a Authorization header with the url i am calling to load a UIWebView. Same thing which is done using ObjC like this

NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData     base64EncodingWithLineLength:80]];
[theRequest setValue:authValue forHTTPHeaderField:@"Authorization"];

I tried in Xamarin some thing like but it is not the Authorization header.

var req = new NSMutableUrlRequest(new NSUrl(urlStr));
var keys = new object[] { "Token"};
var objects = new object[] { tokenVal};
var dictionnary = NSDictionary.FromObjectsAndKeys(objects, keys);
req.Headers = dictionnaire;

I don't see NSMutableUrlRequest has forHTTPHeaderField property to set.

Upvotes: 1

Views: 1488

Answers (1)

Miiite
Miiite

Reputation: 1557

I was also looking for an answer to this. So for anybody trying to do that, the iOS webview actually has a "Header" property, on which you can call "SetValueForKey".

 var request = new NSMutableUrlRequest();
 request.Headers.SetValueForKey(new NSString("MyHeaderValue"), new NSString("MyHeaderKey"));

Upvotes: 1

Related Questions