Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Restsharp的RestCall未通过身份验证,它是通过邮递员进行的_C#_Rest_Http_Postman_Restsharp - Fatal编程技术网

C# Restsharp的RestCall未通过身份验证,它是通过邮递员进行的

C# Restsharp的RestCall未通过身份验证,它是通过邮递员进行的,c#,rest,http,postman,restsharp,C#,Rest,Http,Postman,Restsharp,我正在尝试从需要基本身份验证的REST端点获取信息。 使用邮递员我很好,从电话中获得我需要的信息: 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-

我正在尝试从需要基本身份验证的REST端点获取信息。 使用邮递员我很好,从电话中获得我需要的信息:

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
当我对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);
我错过什么了吗


谢谢

最终我发现使用restsharp进行基本身份验证的正确方法如下

它的工作原理是:

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

您不应该需要
邮递员令牌
-头,而您的授权头在我看来是错误的,我相信它只能包含一个
基本的
,比如
基本的ABC=
,但我不确定,只是以前没有见过这样做。@Tobiastengler我认为邮递员令牌是不相关的,但可能双基本是一个问题。我用一个有效的解决方案来回答自己