RESTSHARP版本> 107:如何实现ntlmauthenticator?
我从同事那里获得了一个源代码,其中使用RestSharp(版本106.15.0)在VB.NET中从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")
如何更改此代码以使其再次工作? 我读到,现在通过clientoptions
使用underefefaultCredentials = true
来定义ntlmauthenticator,但它行不通。
到目前为止,我的方法是:
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)
时,会引发非特定的错误。
I got a source code from a colleague in which using RestSharp (version 106.15.0) in VB.NET retrieves data from a web api.
I updated the RestSharp version to 108.0.1 and the code no longer works. I found out that some things have changed with RestSharp version 107. But I can't get the code to work anymore.
Old Code:
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")
How do I change this code to make it work again?
I read that NtlmAuthenticator is now defined via ClientOptions
with UseDefaultCredentials = true
, but it doesn't work.
My approach so far:
Dim uri As New Uri("url")
Dim restClientOptions As RestClientOptions = New RestClientOptions(uri)
restClientOptions.UseDefaultCredentials = True
restClientOptions.ThrowOnAnyError = True
Dim restClient = New RestClient(restClientOptions)
When running the line Dim restClient = New RestClient(restClientOptions)
, a non-specific error is thrown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在
vb.net
和c#.net
中使用ntlmauthenticator
创建了一个非常简单的控制台应用程序 > V107。vb.net:c#.net
I created a very simple console application in both
VB.NET
andC#.NET
withNtlmAuthenticator
and was able to get the code to work with Restsharp > v107.VB.NET:
C#.NET