- Posts: 22
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Imports System.IO Imports System.Net Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Public Class _Default Inherits System.Web.UI.Page Public Class JsnRPCclient Private id As Integer = 0 Public Property URL As String Public Property Method As String Public Property Parameters As JObject Public Property Response1 As JsonRPCresponse Public Sub New() Parameters = New JObject() Response1 = Nothing End Sub Public Sub New(ByVal URL As String) Me.URL = URL Parameters = New JObject() Response1 = Nothing End Sub Public Function Post() As String Dim jobject As JObject = New JObject() jobject.Add(New JProperty("jsonrpc", "2.0")) jobject.Add(New JProperty("id", System.Threading.Interlocked.Increment(id))) jobject.Add(New JProperty("method", Method)) jobject.Add(New JProperty("params", Parameters)) Dim PostData As String = JsonConvert.SerializeObject(jobject) Dim encoding As UTF8Encoding = New UTF8Encoding() Dim bytes As Byte() = encoding.GetBytes(PostData) Dim requestn As HttpWebRequest = CType(WebRequest.Create(URL), HttpWebRequest) requestn.Method = "POST" requestn.ContentType = "application/json" requestn.KeepAlive = True requestn.ContentLength = bytes.Length Dim writeStream As Stream = requestn.GetRequestStream() writeStream.Write(bytes, 0, bytes.Length) writeStream.Close() Dim response As HttpWebResponse = CType(requestn.GetResponse(), HttpWebResponse) Dim responseStream As Stream = response.GetResponseStream() Dim readStream As StreamReader = New StreamReader(responseStream, encoding.UTF8) Response1 = New JsonRPCresponse() Response1 = JsonConvert.DeserializeObject(Of JsonRPCresponse)(readStream.ReadToEnd()) Response1.StatusCode = response.StatusCode Return Response1.ToString() End Function Public Sub ClearParameters() Me.Parameters = New JObject() End Sub End Class Public Class JsonRPCresponse Public Property id As Integer Public Property result As Object Public Property [error] As String Public Property StatusCode As HttpStatusCode Public Sub New() End Sub Public Overrides Function ToString() As String Return "{""id"":" & id.ToString() & ",""result"":""" & result.ToString() & """,""error"":" & [error] & (If((String.IsNullOrEmpty([error])), "null", """" & [error] & """")) & "}" End Function End Class Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Configure SSL/TLS settings ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls ServicePointManager.ServerCertificateValidationCallback = Function(sender2, certificate, chain, sslPolicyErrors) True Dim Baseurl As String = "https://www.dcsmanagement.com.au/evf/admin/remotecontrol/" Dim client As JsnRPCclient = New JsnRPCclient(Baseurl) client.Method = "get_session_key" client.Parameters.Add("username", "admin") client.Parameters.Add("password", "123456") client.Post() Dim SessionKey As String = client.Response1.result.ToString() 'Console.WriteLine(SessionKey.ToString) TextBox1.Text += SessionKey client.ClearParameters() If (client.Response1.StatusCode = System.Net.HttpStatusCode.OK) Then client.Method = "list_surveys" client.Parameters.Add("sSessionKey", SessionKey) client.Post() End If client.ClearParameters() Dim content As String = client.Response1.result.ToString() ' Read the response content as a string ' Dim jsonObject As JObject = JObject.Parse(content) Dim jsonArray As JArray = JArray.Parse(content) Dim t, i, d As String For Each item As JObject In jsonArray t = item.SelectToken("surveyls_title").ToString i = item.SelectToken("sid").ToString d = "" If t.Contains("<br>") Then Dim StringParts() As String = Split(t, "<br>", 3) d = StringParts(2).ToString t = t.Replace("<br>", " ") Literal1.Text += "<tr><td>" & i.ToString & "</td><td>" & t.ToString & "</td><td>" & d.ToString & "</td><tr>" ElseIf Not t.Contains("<br>") Then d = "---" t = t.Replace("<br>", " ") Literal1.Text += "<tr><td>" & i.ToString & "</td><td>" & t.ToString & "</td><td>" & d.ToString & "</td><tr>" End If Next TextBox1.Text += content End Sub End Class
Please Log in to join the conversation.
Your LimeSurvey version: Version 5.3.31+220815
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.