my VB skills are "BASIC" but I just need to create a simple app that checks if a user exists on website we use which works successfully, if they don't exist allows user to add the user.
the website has given code to read but none to write, so have tried to do it myself, but when I post it replies back.
StatusCode 415 "Unsupported media type"
I know this code is dirty but forgive me don't have much time so just need to get job done.
Dim theclient As New HttpClient()
theclient.BaseAddress = New Uri("https://live2api.xxxxx.co.uk/") 'Base Url
' Add an Accept header for JSON format.
theclient.DefaultRequestHeaders.Accept.Add(New
MediaTypeWithQualityHeaderValue("application/json"))
Dim toEncodeAsBytes As Byte()
Dim thetext As String = apiAccessKey & ":" & apiSecretKey
toEncodeAsBytes =
System.Text.ASCIIEncoding.ASCII.GetBytes(Convert.ToString(thetext))
Dim returnValue As String = System.Convert.ToBase64String(toEncodeAsBytes)
' Add Authorization header
theclient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Basic", returnValue)
' Response.
Dim userdetails As String = "{" & Chr(13) & Chr(34) & "Username" & Chr(34) & ": " & Chr(34) & firstname & "." & lastname & Chr(34) & "," & Chr(13)
userdetails = userdetails & Chr(34) & "Firstname" & Chr(34) & ": " & Chr(34) & firstname & Chr(34) & "," & Chr(13)
userdetails = userdetails & Chr(34) & "Lastname" & Chr(34) & ": " & Chr(34) & lastname & Chr(34) & "," & Chr(13)
userdetails = userdetails & Chr(34) & "Password" & Chr(34) & ": " & Chr(34) & "Password1" & Chr(34) & "," & Chr(13)
userdetails = userdetails & Chr(34) & "Email" & Chr(34) & ": " & Chr(34) & emailaddress & Chr(34) & "," & Chr(13)
userdetails = userdetails & "}"
Dim encode As Byte()
encode = System.Text.ASCIIEncoding.ASCII.GetBytes(Convert.ToString(userdetails))
Dim userdata As String = System.Convert.ToBase64String(encode)
'MessageBox.Show(BKSBuserdetails)
Dim response As HttpResponseMessage = theclient.PostAsync("api/users/createUser", New StringContent(userdata)).Result '
Dim responsetext As String = response.ToString
MessageBox.Show(responsetext)
any help on where I am going wrong would be appreciated
What I have tried:
I tried sending it as a string and encoding it and both came back with same basic error.