身份验证德国铁路 API

Authentication DeutscheBahn API

我需要访问德国火车运营商 Deutsche Bahn 的一些时间 table 信息。我的客户已经设置了一个帐户并订阅了相关的 API.

执行这段代码时,出现错误。

// 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 occurred HResult=-2146232800 Message=Authentication failed because the remote party has closed the transport stream. Source=System StackTrace: at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) InnerException:

@Rup - 非常感谢。

我必须明确设置:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

该应用程序以 Net 4.0 为目标,我假设,通过在 URL 中使用 https,它将隐式使用 SSL。