我是基于网络的解决方案的新手。我正在使用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"
答案 0 :(得分:4)
这就是它所需要的一切......
client.Authenticator = new NtlmAuthenticator();
因此,如果您的IIS设置已将Windows身份验证设置为已启用,则这是您将需要的,Http Basic身份验证不足以通过服务器安全性