RestSharp响应未经授权 [英] RestSharp response unauthorized
问题描述
我是基于Web的解决方案的新手。我正在使用RestSharp库访问一个剩余URL。
我的代码如下:
I am new to web based solutions. I am hitting a rest url using RestSharp library.
My code is as follows:
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 =未经授权
The url returns a json file, when I hit it manually. But I want to use a C# console application to get the json file and save it to the disk. I am getting an unauthorized response when I run the above mentioned code:
response.ResponseStatus= "Unauthorized"
推荐答案
这就是它所需要的。。
client.Authenticator = new NtlmAuthenticator();
因此,如果您的IIS设置已启用Windows身份验证,那么这就是您需要的, Http Basic身份验证不足以通过服务器安全性
So if your IIS settings have Windows Authentication set as enabled, this is what you are going to need, Http Basic authentication is not enough to by pass the server security
这篇关于RestSharp响应未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!