求助:C# HTTP身份验证返回401 unauthorized
代码如下:
// Create the web request
HttpWebRequest request
= WebRequest.Create("http://xxx") as HttpWebRequest;
// Add authentication to request
request.Credentials = new NetworkCredential("username", "password");
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
Console.WriteLine(reader.ReadToEnd());
}
相关推荐
asp.net(c#)判断远程图片是否存在
不错的应用,大家可以拓展到,判断远程文件是否存在等功能
AuthorizeAttribute.Extended:这提供了一个库,将ASP.NET MVC AuthorizeAttribute类上的403错误与401错误分开
AuthorizeAttribute扩展 AuthorizeAttribute Extended基于身份验证和/或授权结果将403(禁止)错误代码与401(未授权)错误代码分开,而ASP.NET的AuthorizeAttribute类仅返回401(未授权)错误代码。 包装状态 AuthorizeAttribute扩展 入门 AuthorizeAttribute Extended的工作原理与上现有的AuthorizeAttribute类完全相同。 添加/更新FilterConfig.cs App_Start\FilterConfig.cs应包含AuthorizeAttribute类。 必须using别名来避免System.Web.Mvc.AuthorizeAttribute类的混淆。 using AuthorizeAttribute = Aliencube . AuthorizeAtt
C#进阶系列 WebApi身份认证解决方案推荐:Basic基础认证
下面小编就为大家带来一篇C#进阶系列 WebApi身份认证解决方案推荐:Basic基础认证。小编觉得挺不错的,现在分享给大家。给大家一个参考。一起跟随小编过来看看吧
身份验证器:.Net Core 5的API参数
认证者 .Net Core 5的API参数
http响应状态码
响应码分五种类型,由它们的第一位数字表示:1xx:信息,请求收到,继续处理2xx:成功,行为被成功地接受、理解和采纳3xx:重定向,为了完成请求,必须进一步执行的动作4xx:客户端错误,请求包含语法错误或者请求无法实现5xx:服务器错误,服务器不能实现一种明显无效的请求



