问题描述
我需要进行 POST 并获取返回的令牌。但是请求/响应只是返回错误 500。
我的功能:
Public Function SendRequest() As String
Dim token As String = ""
Dim data = Encoding.UTF8.GetBytes("{
""Login"": ""login"",""Senha"": ""pass"",""GrantType"": ""password""
}")
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
Dim httpRequest As HttpWebRequest
Dim httpResponse As HttpWebResponse
Try
httpRequest = WebRequest.Create("https://www.pagtel.com.br/Hub360/Contel/api/Login")
httpRequest.Method = "POST"
httpRequest.ContentType = "application/json"
httpRequest.ContentLength = data.Length
Dim requestStream = httpRequest.GetRequestStream
requestStream.Write(data,data.Length)
httpResponse = httpRequest.GetResponse()
Catch wex As WebException
If wex.Status = WebExceptionStatus.ProtocolError Then
httpResponse = wex.Response
Dim erro As String = httpResponse.StatusCode.ToString()
httpResponse.Close()
End If
End Try
Return token
End Function
我更改了登录名和密码。
最奇怪的是,在 Postman 中,它运行得很好。没有错误和状态 200。 但是当在我的应用程序中时,只返回错误 500。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)