【发布时间】:2022-06-13 20:27:31
【问题描述】:
我从一位同事那里得到了一个源代码,其中在 VB.NET 中使用 RestSharp(版本 106.15.0)从 Web api 检索数据。 我将 RestSharp 版本更新为 108.0.1,代码不再有效。我发现 RestSharp 版本 107 发生了一些变化。但我无法再让代码工作了。
旧代码:
Dim restClient As New RestClient(server) With {
.Timeout = 10000,
.Authenticator = New NtlmAuthenticator(),
.ThrowOnAnyError = True
}
Dim response As IRestResponse
Dim restRequest = New RestRequest(sQ, Method.Post)
restRequest.AddHeader("content-type", "application/json")
restRequest.AddHeader(Settings.Default.AppIdKey, Settings.Default.AppIdValue)
restRequest.AddHeader("Accept-Language", "en")
如何更改此代码以使其再次工作?
我读到 NtlmAuthenticator 现在是通过 ClientOptions 和 UseDefaultCredentials = true 定义的,但它不起作用。
到目前为止我的方法:
Dim uri As New Uri("url")
Dim restClientOptions As RestClientOptions = New RestClientOptions(uri)
restClientOptions.UseDefaultCredentials = True
restClientOptions.ThrowOnAnyError = True
Dim restClient = New RestClient(restClientOptions)
在运行Dim restClient = New RestClient(restClientOptions) 行时,会抛出一个非特定的错误。
【问题讨论】:
标签: vb.net restsharp ntlm-authentication