noobiehacker
noobiehacker

Reputation: 1109

AuthenticationHeaderValue can not be set

I can trying to set an authentication value just for testing purposes.
I am not using basic authentication but just a String

VC.Request.Headers.Authorization = new AuthenticationHeaderValue("Secret Password");

It gives me this error that is making me pulling my hair off:

The format of value 'Secret Password' is invalid.

Again I don't want to use basic authentication and I don't know whats wrong, help?

Upvotes: 3

Views: 3547

Answers (2)

CodeCaster
CodeCaster

Reputation: 151674

The class is "documented" as:

Represents authentication information in Authorization, ProxyAuthorization, WWW-Authneticate[sic], and Proxy-Authenticate header values.

By calling the constructor with one parameter, you're using "Secret Password" as scheme, which can only contain tokens (i.e. no spaces). See RFC 2617 for specification.

You might want to call the other constructor overload:

new AuthenticationHeaderValue("MySuperAuthScheme", "Secret Password");

Upvotes: 4

Martin Costello
Martin Costello

Reputation: 10872

I think basic authentication generally uses a username:password syntax, so the client-side code might be pre-validating it to stop you sending "bad" data mistakenly to the server, even though that's what you're intentionally trying to do. Try adding a : and see if that helps.

Upvotes: -2

Related Questions