使用“Flurl库”调用https端点(在我的开发机器上)我收到错误 所以我加了“着名的”
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
跳过证书验证。
这似乎不适用于Flurl(但适用于其他库,如“RestSharp”)
这是我的代码:
public async Task<object> MyMethod()
{
var client = new Url(baseUrl)
.AppendPathSegment(_endpoint)
.SetQueryParam("mbxId", 7)
.WithBasicAuth(username, password)
.WithHeader("cache-control", "no-cache")
.WithHeader("contenttype", "application/json; charset=utf-8")
.WithHeader("Accept", "text/html, application/xhtml+xml, image/jxr, */*");
return await client.GetAsync();
}
如果在拨打电话之前打开“fiddler”并且我确认关于证书问题的消息警告(在这种情况下有效,如果我不首先打开小提琴手,那就不行了)
ServicePointManager.ServerCertificateValidationCallback是否具有全局范围?为什么flurls不考虑这种配置?
---- ----修订
内部异常:
[System.Exception {Flurl.Http.FlurlHttpExceprion}]
消息:
{"Security Error"} Request to https://demo.xxxxx.xxxxxxxxxxxxx.com:8181/dmlm4ws/ws/sessions/sessions?mbxId=7 failed. An error occurred while sending the request.
堆栈跟踪
in Flurl.Http.Configuration.FlurlMessageHandler.<InnerSendAsync>d__2.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 59
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in Flurl.Http.Configuration.FlurlMessageHandler.<SendAsync>d__1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 31
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
in Flurl.Http.Configuration.FlurlMessageHandler.<SendAsync>d__1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 43
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
in Flurl.Http.Configuration.FlurlMessageHandler.<SendAsync>d__1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 47
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in Flurl.Http.FlurlClient.<SendAsync>d__28.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\FlurlClient.cs:riga 202
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
in DLMN.DMLM.<PerformRequest>d__8.MoveNext() in C:\PROGETTI\Progetti\DMLM\DLMN\DLMN\DMLM.cs:riga 90
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
in Flurl.Http.HttpResponseMessageExtensions.<ReceiveJson>d__0`1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\HttpResponseMessageExtensions.cs:riga 26