Forum Discussion

Wendigo's avatar
Wendigo
Occasional Contributor
12 years ago

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

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    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
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

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

    regards,

    /Ole
    SmartBear Software
  • Wendigo's avatar
    Wendigo
    Occasional Contributor
    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 :/
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

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

    thanks,

    /Ole
    SmartBear Software
  • Wendigo's avatar
    Wendigo
    Occasional Contributor
    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
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    you should be able to use

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

    does that work ok?

    /Ole
    SmartBear Software
  • Wendigo's avatar
    Wendigo
    Occasional Contributor
    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]
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    ok.. then just remove them with

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

    ?

    /Ole
    SmartBear Software
  • Wendigo's avatar
    Wendigo
    Occasional Contributor
    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)