我是基于网络的解决方案的新手。我正在使用 RestSharp 库访问休息网址。
我的代码如下:
var cleint = new RestClient("http://REST_URL");
cleint.Authenticator = new HttpBasicAuthenticator("username", "password");
var request = new RestRequest();
request.Method = Method.GET;
request.Resource = "0.json";
IRestResponse response = cleint.Execute(request);
if (response != null && ((response.StatusCode == HttpStatusCode.OK) &&
(response.ResponseStatus == ResponseStatus.Completed)))
{
// var arr = JsonConvert.DeserializeObject<JArray> (response.Content);
}
当我手动点击时,该 url 返回一个 json 文件。但我想使用 C# 控制台应用程序来获取 json 文件并将其保存到磁盘。当我运行上述代码时,我收到未经授权的响应:
response.ResponseStatus= "Unauthorized"
这就是所需要的一切..
client.Authenticator = new NtlmAuthenticator();
因此,如果您的 IIS 设置启用了 Windows 身份验证,这就是您所需要的,Http Basic 身份验证不足以绕过服务器安全
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)