【问题标题】:Get a token from a rest api with vbnet. Method POST使用 vbnet 从 rest api 获取令牌。方法 POST
【发布时间】:2023-02-13 22:10:57
【问题描述】:

我正在尝试从 ws 获取令牌,但到目前为止我还没有成功。 如果我从邮递员那里得到令牌,但从我的 vbnet 应用程序中没有。 我在 vbnet 中使用的代码是:

Dim client = New RestClient("https://xxxxxxxx.com/IntegrationAPI_2/api/login")
Dim request2 = New RestRequest(Method.POST)
request2.AddParameter("application/json", ParameterType.RequestBody)
request2.RequestFormat = DataFormat.Json
request2.AddParameter("Username", UserVar)
request2.AddParameter("Password", PasswVar)
Dim response2 As RestResponse = client.Execute(request2)

在statuscode中vb net中得到的结果是0,但是在postman中是200 ok

我在 visual studio 2015 编程。谢谢

【问题讨论】:

  • Stackoverflow 是一个纯英文网站。请确保您的帖子仅使用英文。
  • 我删除了您问题的非英语版本。请检查并确保所有相关信息都存在。我认为用英语进行一些散文解释会有所帮助。比较How to Ask。并且请考虑使用tour,它可能会为您澄清一些误解。

标签: vb.net


【解决方案1】:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls

URLSERVICE += "?username=" & User & "&password=" & Passw

Dim client = New RestClient("" & URLSERVICE & "")
Dim request = New RestRequest(Method.POST)
request.AddHeader("Content-Type", "application/json")

request.RequestFormat = DataFormat.Json
Dim response As RestResponse = client.Execute(request)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 2021-10-15
    • 2015-09-06
    • 2018-01-20
    • 2023-01-10
    • 1970-01-01
    • 2021-08-25
    相关资源
    最近更新 更多