RestSharp response unauthorized

Deadly 提交于 2019-12-20 01:46:54

问题


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);

  }

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"


回答1:


This is all it needed..

  client.Authenticator = new NtlmAuthenticator();

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



来源:https://stackoverflow.com/questions/29544824/restsharp-response-unauthorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!