gpt4 book ai didi

c# - c# 中的 HTTPS GET REST 请求不适用于 RestSharp

转载 作者:行者123 更新时间:2023-11-30 18:15:34 26 4
gpt4 key购买 nike

我可以使用 postman 成功调用 HTTPS REST GET 请求。

但是当我尝试通过使用带有以下代码的 RestShap(C#、.NET)来调用相同的 HTTPS REST 请求时。

var client = new RestClient("https://testsite.com:7000/abcd/1.0/xyx/games/getgames");
client.Authenticator = new HttpBasicAuthenticator("myusername", "mypassword");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);

我收到以下异常

The underlying connection was closed: An unexpected error occurred on a send.

我尝试使用 Fiddler 捕获请求,但我观察到一个奇怪的事情是请求类型是 HTTP。

fiddler 的错误是

fiddler.network.https> HTTPS handshake to testsite.com (for #45) failed. System.IO.IOException Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. < An existing connection was forcibly closed by the remote host

最佳答案

您需要有 SSL 证书才能使用 https 请求,您可以使用以下代码将 SSL 证书添加到您的请求中

X509Certificate2 certificates = new X509Certificate2();
certificates.Import(...);

client.ClientCertificates = new X509CertificateCollection(){certificate});

关于c# - c# 中的 HTTPS GET REST 请求不适用于 RestSharp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47906037/

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