简体   繁体   English

带有Restsharp的RestCall未通过身份验证,与邮递员一起使用

[英]RestCall with Restsharp not authenticated, it is with Postman

I'm trying to get info from a REST endpoint that requires basic authentication. 我正在尝试从需要基本身份验证的REST端点获取信息。 Using postman I'm fine, getting the information I need from the call: 我可以使用邮递员,可以从电话中获取所需的信息:

GET endpoint/api/workitems?ids=20449& api-version=2.0 HTTP/1.1
Host: xxx.xxx.xxx.50:8080
Authorization: Basic ABC==,Basic ZZZ    cache-control: no-cache
Postman-Token: e6476d89-ec2b-439d-8821-88ef446a03a9

When I do the same with restsharp, I get an Unauthorized error: 当我对restsharp执行相同操作时,会出现未授权错误:

var client = new RestClient("http://xxx.xxx.xxx.50:8080/endpoint/api/workitems?ids=20449& api-version=2.0");
var request = new RestRequest(Method.GET);
request.AddHeader("Postman-Token", "06ea7553-d35e-4743-a516-201d6e3b9084");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Authorization", "Basic ABC==,Basic ZZZ");
IRestResponse response = client.Execute(request);

Am I missing something? 我想念什么吗?

Thanks 谢谢

Eventually I found that the proper way to do the Basic Authentication with restsharp is the following. 最终,我发现使用restsharp进行基本身份验证的正确方法如下。

It works: 有用:

var client = new RestClient("http://xxx.xxx.xxx.50:8080/endpoint/api/workitems?ids=20449& api-version=2.0");
client.Authenticator = new HttpBasicAuthenticator(username, decodedToken);
var request = new RestRequest(Method.GET);
request.AddHeader("Postman-Token", "06ea7553-d35e-4743-a516-201d6e3b9084");
request.AddHeader("cache-control", "no-cache");
IRestResponse response = client.Execute(request);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM