Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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# 如何通过DalSoft.RestClient传递凭据?_C#_Credentials_Networkcredentials_Dalsoft.restclient - Fatal编程技术网

C# 如何通过DalSoft.RestClient传递凭据?

C# 如何通过DalSoft.RestClient传递凭据?,c#,credentials,networkcredentials,dalsoft.restclient,C#,Credentials,Networkcredentials,Dalsoft.restclient,我试图使用对内部服务进行restful调用,该服务要求提供网络凭据(对于我的用例,默认凭据) RestClient的构造函数提供了一个重载来传递IHttpClientWrapper,我可以实现对凭据的处理,但我希望有一个现成的解决方案来将凭据传递给RestClient 如何将凭据传递给DalSoft.RestClient?对于通过标头(如basic或oauth)设置的任何凭据,可以使用标头方法。oauth2承载令牌的示例: dynamic client = new RestClient("htt

我试图使用对内部服务进行restful调用,该服务要求提供网络凭据(对于我的用例,默认凭据)

RestClient
的构造函数提供了一个重载来传递
IHttpClientWrapper
,我可以实现对凭据的处理,但我希望有一个现成的解决方案来将凭据传递给
RestClient


如何将凭据传递给
DalSoft.RestClient

对于通过标头(如basic或oauth)设置的任何凭据,可以使用标头方法。oauth2承载令牌的示例:

dynamic client = new RestClient("http://localhost/");
client
   .Headers(new { Authorization = "Bearer " + bearerToken })
   .MyResource
   .Get();
如果您目前正在谈论kerberos或ntlm,那么没有方法可以做到这一点,但正如您所建议的,您可以实现IHTTPClientRapper来做到这一点。奇怪的是,凭证是使用HttpClientHandler传递给HttpClient的。下面是如何执行此操作的示例:

HttpClientHandler handler = new HttpClientHandler();
handler.Credentials = new NetworkCredential();
HttpClient client = new HttpClient(handler);
我意识到实现IHTTPClientRapper只是为了实现这一点并不理想,因此如果您需要此功能,我将考虑将其添加到ctor中。它看起来是这样的:

HttpClientHandler handler = new HttpClientHandler();
handler.Credentials = new NetworkCredential();
new RestClient("http://localhost/", new Config(handler)); 
从3.0开始,现在支持此更新


感谢您阅读我对Kerberos和NTLM的看法,因为是的,这正是我所说的网络凭据的意思。如果通过构造带有认证信息的HttpHandler的
RestClient
来处理这个问题,那就太好了。我创建了一个请求,请求按照上面所述添加此功能。感谢@ahsteele,我已经实现了此功能。