cancel
Showing results for 
Search instead for 
Did you mean: 

How to get header data from a RAW response into a parameter

Occasional Contributor

How to get header data from a RAW response into a parameter

I need to get a url in the header from a RAW response into a parameter.
How can I get the Location url into that parameter named e.g. location ?

The complete raw response (including body) looks like this:
----------------------
HTTP/1.1 201 Created
Server: some-server-idenifier
Location: https://some-server:some-port/some/url/unique-token
Date: Mon, 18 Jun 2012 07:11:11 GMT
Content-Type: application/some-content-type
Content-Length: 2

[]
----------------------

BR
/Wendigo
10 REPLIES 10

Re: How to get header data from a RAW response into a parame

Hi,

what kind of requests are these two? (REST, SOAP, HTTP?)

regards,

/Ole
SmartBear Software


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
Occasional Contributor

Re: How to get header data from a RAW response into a parame

Hi
They are https calls.
I was thinking of having a DataGen (script) to get the url but can't figure out how to parse the response in a correct manner :/

Re: How to get header data from a RAW response into a parame

Hi,

ok - are these HTTP TestSteps ? or REST ? (need to know so I can create the right script..)

thanks,

/Ole
SmartBear Software


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
Occasional Contributor

Re: How to get header data from a RAW response into a parame

HTTP test steps and I can retrieve the complete response (as described above) with:
def str = new String(testRunner.testCase.testSteps["init"].testRequest.response.rawResponseData)
return str
.. in a DataGen

Re: How to get header data from a RAW response into a parame

Hi,

you should be able to use

def str = testRunner.testCase.testSteps["init"].testRequest.response.responseHeaders["Location"]
...

does that work ok?

/Ole
SmartBear Software


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
Occasional Contributor

Re: How to get header data from a RAW response into a parame

Almost
But I ger a[ at the start of the string and a ] at the end.
Like:
[https://some-server:some-port/some/url/unique-token]

Re: How to get header data from a RAW response into a parame

Hi,

ok.. then just remove them with

str = str.substring( 1, str.length()-2)

?

/Ole
SmartBear Software


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
Occasional Contributor

Re: How to get header data from a RAW response into a parame

Getting:
No signature of method: java.util.ArrayList.length() is applicable for argument types: () values: [] Possible solutions: last(), get(int), get(int), getAt(java.lang.String), getAt(java.util.Collection), each(groovy.lang.Closure)
Highlighted

Re: How to get header data from a RAW response into a parame

duh - I'm sorry - it should have been

def str = testRunner.testCase.testSteps["init"].testRequest.response.responseHeaders["Location"][0]

is that better?

/Ole
SmartBear Software


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors