I'm building an experimental application in VB.NET to test how easy (or otherwise) it is to import/export data via the REST API. I've built a Form to hold the URL (http://<server>/IDORequestService), Username, Password and required Configuration and have also used TimBoyden's PySyteline site(https://pysyteline.boyden.app/) for a bit of guidance.
The first step is to query the server for a list of available Configurations and to validate that the required Configuration exists. This bit works fine. I have a set of message boxes to show me what is going to be sent and what comes back.
The problem comes when I try to get the session token for which the response is 401 Unauthorised. Tim's example code appears to hand the credentials on in plaintext. I've seen other examples on the web which suggest I should specify Basic authentication and encode the credentials in Base64.
I've tried both but get the same response each time. So I'm presumably being dumb or it's something in CSI. I'm using the sa account so privileges shouldn't be an issue but I have a dim recollection from previous experiments with the .NET ASMX interface that there are some permission setup requirements.
Any guidance would be much appreciated.
Thanks in advance
Public TokenSuffix As String = "/json/token/"
…...
Try
RESTUrl = txtURL + TokenSuffix + txtConfig
MessageBox.Show(RESTUrl)
'Get Session Token from Webservice
'Create the initial request for the Configuration List
Dim TokenRequest As HttpWebRequest = HttpWebRequest.Create(RESTUrl)
TokenRequest.Proxy = Nothing
TokenRequest.UserAgent = "Test"
Dim Encoded As String = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(txtUser + ":" + txtPassword))
TokenRequest.Headers.Add("Authorization", "Basic " + Encoded)
'TokenRequest.Headers.Add("UserId:" + txtUser + "Password:" + txtPassword)
'Create the Response and Reader
Dim TokenResponse As HttpWebResponse = TokenRequest.GetResponse
Dim TokenResponseStream As System.IO.Stream = TokenResponse.GetResponseStream
'Create new Stream Reader
Dim TokenStreamReader As New System.IO.StreamReader(TokenResponseStream)
Data = TokenStreamReader.ReadToEnd
TokenStreamReader.Close()
MessageBox.Show(Data)
Catch Weberror As Exception
'Expected exception is Invalid Credentials
MessageBox.Show(Weberror.Message)
End Try