How to use the invoke code activity to request an server side data

Hi, my project want to get some data from server side api via httprequset , I think that we can invoke code which can send remove requset . how to developper . i am not familer with ?
thanks apprecaite.

Hi @Donner,

Yes you can get the data from the server side using Invoke code activity

based on your requirement you need to pass the input and output arguments to invoke code activity.
Refer the below code to get the data from the API.

Dim serviceUrl As String = "http://localhost:17757/VB/Services/Service.svc"
    Dim input As Object = New With { _
                    .name = txtName.Text.Trim(), _
                    .age = txtAge.Text.Trim() _
    Dim inputJson As String = (New JavaScriptSerializer()).Serialize(input)
    Dim httpRequest As HttpWebRequest = DirectCast(WebRequest.Create(New Uri(serviceUrl & "/GetData")), HttpWebRequest)
    httpRequest.Accept = "application/json"
    httpRequest.ContentType = "application/json"
    httpRequest.Method = "POST"
    Dim bytes As Byte() = Encoding.UTF8.GetBytes(inputJson)
    Using stream As Stream = httpRequest.GetRequestStream()
        stream.Write(bytes, 0, bytes.Length)
    End Using
    Using httpResponse As HttpWebResponse = DirectCast(httpRequest.GetResponse(), HttpWebResponse)
        Using stream As Stream = httpResponse.GetResponseStream()
            outputStr = (New StreamReader(stream)).ReadToEnd()
        End Using
    End Using

outputStr is the final output of the API.



Dear :
I am so sorry to reply to you so late.

  1. when I kick the code into a consoleApp, the visual studio show a red line under JavaScriptSerializer meaning the JavaScriptSerializer class is not found. could you tell me which namespace the JavaScriptSerializer is located and how i would get the namespace references.
  2. what kind of uri is available in the HttpWebRequest ? eg, common restful api


Hi, i am also facing the same issue.
Anyone please tell me the reference for javascript serializer to include it in uipath studio

Hi @Donner @DeviEttiyan

Just for future reference, it’s this one: