I am trying to get a bearer token from an identity server using the WebRequest Class because the program has to work with .NET 2.0, and the port from where I am getting the token is 10000.
I tried creating the WebRequest like
- identityURL:10000/getToken
- http://identityURL:10000/getToken
but neither one works. The first returns an "Unkown URL Prefix"-Error and the second one a "400 Bad Request"-Error.
Is there any other way to get the token under .NET 2.0 ?
Thank you very much in advance for your help.
-Simon
Edit:
Using wc As New WebClient()
Dim postData As String = "grant_type=" + sTokenGrantType + "&username=" + sIdentityServerClientName + "&password=" + sIdentityServerClientSecret + "&scope=Api"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
Dim responseArray As Byte()
wc.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded")
wc.Headers.Add(HttpRequestHeader.ContentLength, byteArray.Length.ToString)
wc.Headers.Add(HttpRequestHeader.UserAgent, "User-Agent: PostmanRuntime/7.15.0")
wc.BaseAddress = sIdentityServerURL
responseArray = wc.UploadData("/getToken", "POST", byteArray)
MsgBox(responseArray)
End Using
I tried using the WebClient class but that results in the following error: "An exception occurred during a WebClient request."
SOLVED (see below)