Hi
i am trying to connect to the Mobicontrol API using VB.NET but im not getting very far.
Has anybody done this?
Are there any examples?
It doesnt matter what i try i always get the response 'Bad Request'
thanks
gareth
Hi
i am trying to connect to the Mobicontrol API using VB.NET but im not getting very far.
Has anybody done this?
Are there any examples?
It doesnt matter what i try i always get the response 'Bad Request'
thanks
gareth
Hi,
There are probably more elegant / efficient solutions but the code i have used to return the token is below. i have used the Newtonsoft Json package to help parse the response.
Function access_token()
Dim wHeader As WebHeaderCollection = New WebHeaderCollection()
wHeader.Clear()
Dim clientid As String = "Enter your client id"
Dim clientsecret As String = "Enter your client secret"
Dim idsecret As String
idsecret = clientid + ":" + clientsecret
Dim encodedidsecret = System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(idsecret))
Dim token As String
Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create("https://Enter you domain/MobiControl/api/token")
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
Dim outgoingQueryString As NameValueCollection = HttpUtility.ParseQueryString(String.Empty)
outgoingQueryString.Add("grant_type", "password")
outgoingQueryString.Add("username", "Enter your username")
outgoingQueryString.Add("password", "Enter your password")
outgoingQueryString.Add("client_id", clientid)
outgoingQueryString.Add("client_secret", clientsecret)
outgoingQueryString.Add("content-Length", 53)
outgoingQueryString.Add("Host", "Enter your domain without https://")
Dim postBytes As Byte() = New ASCIIEncoding().GetBytes(outgoingQueryString.ToString())
Dim poststream As Stream = request.GetRequestStream
poststream.Write(postBytes, 0, postBytes.Length)
poststream.Flush()
poststream.Close()
Dim sresponse As String
Using response As WebResponse = request.GetResponse()
Using streamReader As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
sresponse = streamReader.ReadToEnd
Dim json1 As String = "{'root': " & sresponse & " }"
Dim doc As XmlDocument = JsonConvert.DeserializeXmlNode(json1)
Dim nodes As XmlNodeList = doc.DocumentElement.SelectNodes("/root")
For Each node As XmlNode In nodes
token = node.SelectSingleNode("access_token").InnerText
Next
End Using
End Using
Return token
End Function
Hello gareth,
i've never try but try for to begin try this on your browser
https://servername or IP/MobiControl/api/docs/index
it's the document about api of mobicontrol
after follow the help in this page.
After for to call a method in vb net if you can't find any sample
find a example in c# and go to -> https://converter.telerik.com/
tell us ..
Hi,
thank you for the response. i managed to get this working in the end
thanks
Gareth
Hi Gareth Perry,
Thanks for confirming that your issue has been resolved by you. Can you please share the approach you took to find resolution, so that other viewers experiencing the same issue may find 'solution' from your post?
SOTI would be very happy to mark your reply as "solution" for this post.
Thanks & Regards,