gpt4 book ai didi

c# - 如何将 System.Net.ICredentials 传递给 API?

转载 作者:太空狗 更新时间:2023-10-30 00:50:37 24 4
gpt4 key购买 nike

首先,提供凭据以使用所述 API 进行身份验证:

Webservice.Authenticate.Credential credential = new Webservice.Authenticate.Credential
{
Username = "myUserName",
Password = GetMD5("myPassword"), // See below for a MD5 encoding example method
ApplicationId = new Guid("00000000-0000-0000-0000-000000000000"), //YOUR ID HERE
IdentityId = new Guid("00000000-0000-0000-0000-000000000000") //Default is empty guid (no need to edit this)
};

如果我尝试直接将凭据用作 Icredentials,如 _service.Credentials = credential;,则会发生以下错误:

无法将类型 auth.credential 隐式转换为 system.net.icredentials。我试图转换它,但它没有正常工作。

后来,我尝试在调用另一个服务时以这种方式使用凭据。但是,我不确定如何传递凭据。

TransactionService.TransactionService _service = new TransactionService.TransactionService();
TransactionService.TransactionSearchParameters _params = new TransactionService.TransactionSearchParameters();
_service.Credentials = new NetworkCredential(credential.Username, credential.Password);

最佳答案

System.Net.ICredentials是一个集合。

尝试:

_service.Credentials.Add("uri:my.uri"
, "authenticationType"
, new NetworkCredential(credential.Username, credential.Password)
);

关于c# - 如何将 System.Net.ICredentials 传递给 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30740285/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com