c# - ASP.NET Core 2.2 中面临的问题“提供的 URI 方案 'https' 无效;应为 'http'。\r\n参数名称:通过”
问题描述
在 asp.net core 2.2 中使用 Galileo Flight UAPI API 时出错。调用异步方法时出现一个错误
提供的 URI 方案“https”无效;预期的“http”。参数名称:via
我已根据 .net 核心要求更新了 lib 并更改了 BasicHttpBinding
我已经根据搜索 google 和 Stackoverflow 更改了代理
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.AirLowFareSearchPort))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Ntlm;
result.TransferMode = System.ServiceModel.TransferMode.Buffered;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
AirLowFareSearchPortTypeClient client =
new AirLowFareSearchPortTypeClient(AirLowFareSearchPortTypeClient.EndpointConfiguration.AirLowFareSearchPort, uRL + "/AirService");
client.ClientCredentials.UserName.UserName = username;
client.ClientCredentials.UserName.Password = password;
var httpHeaders = Helper.ReturnHttpHeader(username, password);
client.Endpoint.EndpointBehaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders));
SessionContext context = new SessionContext();
var serviceResponse = await client.serviceAsync(context, lowFareSearchReq);
解决方案
创建自己的 BasicHttpBinding 对象并设置“Transport”Security.Mode 和其他属性,分配给 PortType 客户端。这是代码。
System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
binding.MaxBufferSize = int.MaxValue;
binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.AllowCookies = true;
binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
binding.TransferMode = System.ServiceModel.TransferMode.Buffered;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
var endpoint = new EndpointAddress(uRL + "/AirService");
//AirLowFareSearchPortTypeClient client = new AirLowFareSearchPortTypeClient(AirLowFareSearchPortTypeClient.EndpointConfiguration.AirLowFareSearchPort, uRL + "/AirService");
AirLowFareSearchPortTypeClient client = new AirLowFareSearchPortTypeClient(binding, endpoint);
推荐阅读
- javascript - 如何使用 dash.js 立即更改破折号视频的质量(空加载缓冲区)?
- javascript - 如何在 React Native 中使用相同的状态调用获得不同的结果?
- c# - 如何使用 C# 反序列化这个 xml 文档,我只对 ComplianceInfo 部分感兴趣?
- grammar - 线性语法,导出一个词
- php - 用户尚未更新的表单更新字段 - PHP Query
- python - 从使用 Power BI 的网站抓取数据 - 从网站上的 Power BI 检索数据
- c++ - 将输出压缩为单行
- arduino - Arduino SIM800L Firestore 数据库安全规则
- c# - c#在选择列表框中的另一个项目之前要求保存更改
- javascript - 使用 chromedp,从 *runtime.RemoteObject 中获取一个 javascript 对象/数组