There are so many APIs that we cannot use directly. Some of them require an authorized Token first and then we can use that Token to Authenticate that API.
The following is sample code to authenticate an API:
Dim WebServiceURI As String = "API Url"
Dim webrequestobj As HttpWebRequest = DirectCast(WebRequest.Create(WebServiceURI), HttpWebRequest)
Dim soapAction = ""
Dim WebServiceData As StringBuilder = New StringBuilder
Dim WebServiceByteData As Byte() = Encoding.UTF8.GetBytes(WebServiceData.ToString)
webrequestobj.Method = "GET"
webrequestobj.ContentType = "application/json"
webrequestobj.Credentials = CredentialCache.DefaultCredentials
webrequestobj.Headers.Add(HttpRequestHeader.Authorization, "AuthoreizeToken")
Try
Using Response As HttpWebResponse = TryCast(webrequestobj.GetResponse(), HttpWebResponse)
Dim reader As New StreamReader(Response.GetResponseStream())
Dim str As String = reader.ReadLine()
End Using
Catch ex As Exception
End Try