Discussion

1
Replies
737
Views
kishoreRaju Member since 2017 7 posts
virtusa polaris
Posted: April 24, 2018
Last activity: November 6, 2018

Dynamic Rest Service Response using openspan automation

Here we can see how to pass the Rest url dynamically and get the response.

1) first create one windows for with one label, textbox and button. [See the attachment]

2) create an automation file [see the attachment]

3) Made the below changes in Script.

using System;

using System.Collections;

using System.Data;

using System.Diagnostics;

using System.IO;

using System.Linq;

using System.Windows.Forms;

using System.Xml;

using System.Collections.Generic;

using System.Net;

using System.Text;

namespace Dynamic.Script_8D5A918544C6840

{

// Script generated by Pega Robotics Studio 8.0.1064.0

// Please use caution when modifying class name, namespace or attributes

[OpenSpan.TypeManagement.DynamicTypeAttribute()]

[OpenSpan.Design.ComponentIdentityAttribute("Script-8D5A918544C6840")]

public sealed class Script

{

public void RestCall (string url, out string outresponse)

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.Method = "GET";

request.ContentType ="application/json";

request.Accept = "application/json";

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

string response = GetRESTResponse(request);

outresponse = response;

}

public string GetRESTResponse(HttpWebRequest request)

{

string restResponse = string.Empty;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())

{

if (response.StatusCode == HttpStatusCode.OK)

{

using (Stream responseStream = response.GetResponseStream())

{

if (responseStream != null)

{

StreamReader reader = new StreamReader(responseStream);

restResponse = reader.ReadToEnd();

}

}

}

}

return restResponse;

}

}

}

***Updated by moderator: Lochan to mark post as discussion and Community Shared Knowledge***

Robotic Process Automation Developer Knowledge Share
Share this page LinkedIn