I created this code in VB.Net and it gives an error message. This is the error in this sentence Dim resp As Dynamic = JObject.Parse(response.Content)
.
Private Function GetBearerToken() As String
Try
Dim client = New RestClient(Config_class.tokenurl)
Dim request = New RestRequest(Method.POST)
request.AddHeader("cache-control", "no-cache")
request.AddHeader("content-type", "application/x-www-form-urlencoded")
request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=" & client_id & "&client_secret=" client_secret, ParameterType.RequestBody)
Dim response As IRestResponse = client.Execute(request)
Dim resp As Dynamic = JObject.Parse(response.Content)
Dim token As String = resp.access_token
Return token
Catch ex As Exception
End Try
Return ""
End Function
Private Function GetBearerToken() As String
Try
Dim client = New RestClient(Config_class.tokenurl)
Dim request = New RestRequest(Method.POST)
request.AddHeader("cache-control", "no-cache")
request.AddHeader("content-type", "application/x-www-form-urlencoded")
request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=" & client_id & "&client_secret=" client_secret, ParameterType.RequestBody)
Dim response As IRestResponse = client.Execute(request)
Dim resp As Dynamic = JObject.Parse(response.Content)
Dim token As String = resp.access_token
Return token
Catch ex As Exception
End Try
Return ""
End Function
CodePudding user response:
What is 'Dynamic'? Try 'JObject' as the type, according to the documentation for JObject:
Dim resp As JObject = JObject.Parse(response.Content)
CodePudding user response:
The problem is in the Dim resp As Dynamic = JObject.Parse(response.Content) (namespace system Dynamic type expected)