Author Topic: Workflow - REST - Response Header  (Read 43 times)

0 Members and 1 Guest are viewing this topic.

Offline Quizmaster

  • Flying Nurse
  • Seasonal Competition Team
  • *
  • Posts: 23301
    • Smokey's Security Forums
  • .: Surf Queen
Workflow - REST - Response Header
« Reply #1 on: February 09, 2018, 08:15:11 PM »
Workflow - REST - Response Header
9 February 2018, 5:22 pm

A question from @epkpej was asked on another of my Articles

Using the REST Generator (Response Content) in Workflow 7.6

https://www.symantec.com/connect/articles/using-rest-generator-response-content-workflow-76

They wanted to get the "Response Header" from a POST Request.

Unfortunately this isn't possible using the REST Generator. It isn't exposed in the components that are generated by the tool.

Please vote on the Idea/Feature Request:

Workflow - Add possibility to retrieve Response Header data using REST Generator

As an alternative you can swap to a Code (Script) Component

https://www.symantec.com/connect/articles/code-script-component

https://www.symantec.com/connect/content-external/workflow-id_LogicBase....

Now we need to add a couple of Inputs

1. Inputs

URL - Text

HeaderValue - Text

2. Result Variable

Result Variable Type - Text

Result Variable Name - Header

3. Source Code

Namespaces

System.Net

System.IO

Now for the code

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

request.Method = "GET";

request.ServicePoint.Expect100Continue = false;

request.ContentType = "application/json";

using (WebResponse response = request.GetResponse())

{

using (StreamReader reader = new StreamReader(response.GetResponseStream()))

{

//responseString = reader.ReadToEnd();

string header = response.Headers[HeaderValue];

return header;

}

}

As you can see the URL is being used in the first line

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);And the Header in a few down

string header = response.Headers[HeaderValue];This makes the code a little more resuable but there is lots more you can do.

4. Test Page

Now we need an API to test

https://swapi.co/

If we test it in Postman

https://swapi.co/api/people/1There are a number we can chose from, lets use Etag.

Etag

145c70f4eca80b4752674d42e5bf1bcf

Now you might wish to return the collection of headers and loop through them and find the value you wish either in code or with other WF components.

---

If you do need to work with REST the Generator should cover most scenarios and I've written a set of Articles:

Workflow - REST Generator

https://www.symantec.com/connect/articles/workflow-rest-generator

Workflow - REST Generator

Using the REST Generator in Workflow 7.6

Using the REST Generator (GET) in Workflow 7.6 with Mobility Suite

Using the REST Generator (Headers) in Workflow 7.6 with Mobility Suite

Using the REST Generator (POST) in Workflow 7.6 with Mobility Suite

Using the REST Generator (Response Content) in Workflow 7.6

Using the REST Generator (PATHs) in Workflow 7.6

Workflow - Read Write JSON

Workflow - REST - Response Header



Source: Symantec Connect - Security - Articles

>> To obtain the full Symantec Connect Security News article, click the link in the first post line <<

 


Except where otherwise stated, all content, graphics, banners and images included © 2006 - 2018 Smokey Services™ -- All rights reserved
Design board graphics, banners and images by DSTM & PseFrank

This site does not store profiling-, tracking-, third-party and/or any other non-essential cookie(s) on client computers and is fully compliant with the EU ePrivacy Directive
Smokey's does not use any Web Analytics/Analysis Service, and also does not use any browser fingerprinting techniques



Smokey's also provides free fully qualified Log / Malware Analysis & Removal Help and System Health Checks