我正在使用 nuget 包Microsoft.Net.Http
添加HttpClient
到我的 PCL 域库。
我想设置自定义网络凭据,但由于此错误而无法设置:
代码 :
HttpClientHandler handler = new HttpClientHandler();
ICredentials credentials = new NetworkCredential("username", "password", "domain");
handler.Credentials = credentials;
_client = new HttpClient(handler);
错误 :
错误 5 无法将类型“System.Net.ICredentials [c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile78\System.Net.Primitives.dll]”隐式转换为“ System.Net.ICredentials' C:[截断]\ApiClient.cs 26 35 DeltekApi
问题是networkcredentials
我提供的实现了 nuget 添加的实现ICredentials
,而接口HttpClient
想要的是 PCL.Net Portable Subset
版本。
真的想不出解决这个问题的好方法吗?