C# 身份验证DeutscheBahn API
我需要从德国火车运营商德国铁路公司获取一些时刻表信息。我的客户已经建立了一个帐户并订阅了相关的API 执行此代码时,我得到一个错误C# 身份验证DeutscheBahn API,c#,authentication,openapi,C#,Authentication,Openapi,我需要从德国火车运营商德国铁路公司获取一些时刻表信息。我的客户已经建立了一个帐户并订阅了相关的API 执行此代码时,我得到一个错误 // Create request var req = (HttpWebRequest)WebRequest.Create("https://api.deutschebahn.com/fahrplan-plus/v1/location/Berlin"); req.Accept = "application/json"; req.Headers.Add("Author
// Create request
var req = (HttpWebRequest)WebRequest.Create("https://api.deutschebahn.com/fahrplan-plus/v1/location/Berlin");
req.Accept = "application/json";
req.Headers.Add("Authorization", "Bearer <My Access Token>");
req.Method = "GET";
using (WebResponse response = req.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader responseReader = new StreamReader(responseStream))
{
// Do something
}
发生System.IO.IOException异常
HResult=-2146232800
Message=身份验证失败,因为远程方已关闭传输流。
来源=系统
堆栈跟踪:
位于System.Net.Security.SslState.StartReadFrameByte[]缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest
内部异常:
@Rup-非常感谢你 我必须明确地设置:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
应用程序的目标是Net 4.0,我假设,通过在URL中使用https,它将隐式使用SSL。由于这是一个SSL错误,您能否尝试强制.Net使用TLS 1.2,看看这是否有帮助?