Problem creating a login user via RESTful API in VB.NET
Hello all, I have the below code with which I am trying to create a login user via the RESTful API in VB.NET. The API returns that this is an invalid JSON but when I validate the JSON via any online validation site it comes back as valid. Does anyone have an idea as far as why it may be failing?
- ' Creates the JSON web request and returns the results
- Private Function SendRequest(uri As Uri, jsonDataBytes As Byte(),contentType As String, method As String) As String
-
- ' Create initial request
- Dim req As WebRequest = WebRequest.Create(uri)
- req.ContentType = contentType
- req.Method = method
- req.ContentLength = jsonDataBytes.Length
- ' Establish request stream
- Dim stream = req.GetRequestStream()
- stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
- stream.Close()
- ' Retrieve response
- Dim response = req.GetResponse().GetResponseStream()
- ' Parse response
- Dim reader As New StreamReader(response)
- Dim res = reader.ReadToEnd()
- reader.Close()
- response.Close()
- ' Return JSON result
- Return res
- End Function
- Public Function CCC_Test_API_AddUser() As String
- CCC_Test_API_AddUser = Nothing
-
- Dim jsonString As String
- jsonString = "{""operation"":{""Details"":{""USERNAME"":""ThisIsATest"",""FIRSTNAME"":""Test"",""LASTNAME"":""User"",""EMAIL"":""TUser@test.com"",
- ""PHONEFACTOR_USERNAME"":""ThisIsATest""}}}"
- ' Work around to skirt SSL Certificate Validation Checking
- System.Net.ServicePointManager.ServerCertificateValidationCallback = _
- Function(se As Object, _
- cert As System.Security.Cryptography.X509Certificates.X509Certificate, _
- chain As System.Security.Cryptography.X509Certificates.X509Chain, _
- sslerror As System.Net.Security.SslPolicyErrors) True
- Dim siteUri As New Uri("https://server:7272/restapi/json/v1/user?AUTHTOKEN=F6C0CD37-5BB9-44BE-8331-FA4BC64C6071&INPUT_DATA=")
-
- Dim data = Encoding.UTF8.GetBytes(jsonString)
- Dim result_post = SendRequest(siteUri, data, "text/json", "POST")
- Return result_post
-
- End Function
New to ADSelfService Plus?