对象是从请求的API接收承载令牌。我可以使用邮递员完成此操作,但想在我的应用程序中实现。
我尝试了许多不同的通话方式,但是这似乎与我最接近。我目前正在获取状态码:使用以下脚本时出现400错误的请求。
有人有解决此问题的想法吗?
Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(user & ":" + password))
Dim request As HttpWebRequest = HttpWebRequest.Create("https://oauth2.url.com/token")
request.Proxy = Nothing
request.Method = "GET"
request.ContentType = "application/json"
request.Headers.Add("client_id", "clientid")
request.Headers.Add("client_secret", "clientsecret")
request.Headers.Add("grant_type", "authorization_code")
request.Headers.Add("auth_url", "https://oauth2.url.com/authorization")
request.Headers(HttpRequestHeader.Authorization) = "Basic " & credentials
request.Headers.Add("redirect_uri", "http://localhost:5000/auth/callback")
'create the response and reader
Dim Response As HttpWebResponse = request.GetResponse
Dim ResponseStream As System.IO.Stream = Response.GetResponseStream
'Create Stream reader
Dim StreamReader As New System.IO.StreamReader(ResponseStream)
Dim data As String = StreamReader.ReadToEnd
StreamReader.Close()
'get the data
Dim jsonString = data.ToString.Replace("'", "''")