我正在尝试使用RestSharp在我的本地机器上测试API调用,下面是代码:
在
这是否意味着我需要尝试设置https://localhost而不是http://localhost来调用https地址的API? 更新 根据@Shai_Aharoni的答案,我已将我的代码更新如下。然而,我仍然遇到相同的错误。
...
var client = new RestClient("https://[API URL]");
var request = new RestRequest( Method.POST);
request.AddParameter("session", this, ParameterType.RequestBody);
IRestResponse<SessionOut> response = client.Execute<SessionOut>(request);
return response.Data.session.id;
在
响应
中,我收到了一个错误提示,告诉我请求被中止,因为它“无法创建SSL/TLS安全通道”。这是否意味着我需要尝试设置https://localhost而不是http://localhost来调用https地址的API? 更新 根据@Shai_Aharoni的答案,我已将我的代码更新如下。然而,我仍然遇到相同的错误。
string pathToYourClientCert = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "[my certificate file");
var client = new RestClient("[API URL]/");
client.ClientCertificates = new X509CertificateCollection();
client.ClientCertificates.Add(new X509Certificate(pathToYourClientCert));
var request = new RestRequest( Method.POST);
request.AddParameter("session", this, ParameterType.RequestBody);
IRestResponse<SessionOut> response2 = client.Execute<SessionOut>(request);