1
我正在使用基本授权编写RESTful服务。wcf 401并要求在RESTful服务中登录/密码
这是我做的时候没有授权头存在,或者当有错误UN /密码
//Get authorization header
var auth = HttpContext.Current.Request.Headers.GetValues("Authorization");
if (auth == null)
{
outgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
return false;
}
//Parse auth header:
var authString = auth[0];
String loginName, password;
try
{
var decbuff = Convert.FromBase64String(authString.Replace("Basic ", ""));
loginName = System.Text.Encoding.UTF8.GetString(decbuff).Split(':')[0];
password = System.Text.Encoding.UTF8.GetString(decbuff).Split(':')[1];
}
catch
{
outgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
outgoingResponse.StatusDescription = "Invalid Authorization header";
return false;
}
当我看着菲德勒我看到这一点:
它的工作原理确定与我的客户端(Android),但我希望这项服务可以通过浏览器或其他浏览器浏览。如果我发送401,我如何让资源管理器询问联合国/密码?我需要指定一些东西吗?
谢谢