/// <summary> /// Try to parse the given text. /// </summary> /// <param name="Text">A text representation of a HTTP basic authentication header.</param> /// <param name="BasicAuthentication">The parsed HTTP basic authentication header.</param> /// <returns>true, when the parsing was successful, else false.</returns> public static Boolean TryParse(String Text, out HTTPBasicAuthentication BasicAuthentication) { BasicAuthentication = null; if (Text.IsNullOrEmpty()) { return(false); } var splitted = Text.Split(new Char[] { ' ' }); if (splitted.IsNullOrEmpty()) { return(false); } if (splitted[0].ToLower() == "basic") { var usernamePassword = splitted[1].FromBase64().Split(new Char[] { ':' }); if (usernamePassword.IsNullOrEmpty()) { return(false); } BasicAuthentication = new HTTPBasicAuthentication(usernamePassword[0], usernamePassword[1]); return(true); } return(false); }
/// <summary> /// Set the HTTP Authorization header field. /// </summary> /// <param name="Authorization">Authorization.</param> public HTTPRequestBuilder SetAuthorization(HTTPBasicAuthentication Authorization) { this.Authorization = Authorization; return(this); }
/// <summary> /// Try to parse the given text. /// </summary> /// <param name="Text">A text representation of a HTTP basic authentication header.</param> /// <param name="BasicAuthentication">The parsed HTTP basic authentication header.</param> /// <returns>true, when the parsing was successful, else false.</returns> public static Boolean TryParse(String Text, out HTTPBasicAuthentication BasicAuthentication) { BasicAuthentication = null; if (Text.IsNullOrEmpty()) return false; var splitted = Text.Split(new Char[] { ' ' }); if (splitted.IsNullOrEmpty()) return false; if (splitted[0].ToLower() == "basic") { var usernamePassword = splitted[1].FromBase64().Split(new Char[] { ':' }); if (usernamePassword.IsNullOrEmpty()) return false; BasicAuthentication = new HTTPBasicAuthentication(usernamePassword[0], usernamePassword[1]); return true; } return false; }
/// <summary> /// Set the HTTP Authorization header field. /// </summary> /// <param name="Authorization">Authorization.</param> public HTTPRequestBuilder SetAuthorization(HTTPBasicAuthentication Authorization) { this.Authorization = Authorization; return this; }