Extract response values and store them in session

Hi,
My response returns “|0|hiddenField|__EVENTTARGET||0|hiddenField|__EVENTARGUMENT||0|hiddenField|__LASTFOCUS||7008|hiddenField|__VIEWSTATE|/wEPDwUKMTgyMzU4MzE3OA8WBB4N…”.
It’s seperated by “|” and I would like to extract the response to get some values and store them to session:
def postUpdatePanel(name: String, url: String) = http(name).post(url)
.check(
bodyString.transform(
_.map(
string => {
var viewStateResponse = string
var viewStateKeyWord = “|__VIEWSTATE|”
var startIndex = viewStateResponse.indexOf(viewStateKeyWord)
viewStateResponse = viewStateResponse.substring(startIndex + viewStateKeyWord.length,viewStateResponse.length-1)
var endIndex = viewStateResponse.indexOf("|")
viewStateResponse = viewStateResponse.substring(0,endIndex)

viewStateResponse
}
)
).saveAs(“viewState”),
bodyString.transform(
_.map(
string => {
var viewStateResponse = string
var viewStateKeyWord = “|__EVENTARGUMENT|”
var startIndex = viewStateResponse.indexOf(viewStateKeyWord)
viewStateResponse = viewStateResponse.substring(startIndex + viewStateKeyWord.length,viewStateResponse.length-1)
var endIndex = viewStateResponse.indexOf("|")
viewStateResponse = viewStateResponse.substring(0,endIndex)

viewStateResponse
}
)
).saveAs(“eventArgument”)
)
.param("""__VIEWSTATE""", “”"${viewState}""")
.param("""__EVENTARGUMENT""", “”"${eventArgument}""")

it’ just able to store “viewState”. With “eventArgument” it throws: “[ERROR] i.g.h.a.HttpRequestAction - No attribute named ‘eventArgument’ is defined”.
How can I achieve this?

Thanks in advance.

Wouldn’t it be way easier with a regex?

Hi Stéphane,
I’m not familiar with regex, could you please give your suggestion about regex in this case?
Moreover, i need to store 2 session from one response. how can i do that?

Thanks.

To save more than one value, you’d want to do this:

.check(regex(“thing1=([A-Za-z]+)”).saveAs(“thing1”),
regex(“thing2=([A-Za-z]+)”).saveAs(“thing2”))

As for regexes, I recommend http://www.regular-expressions.info/ as a resource. Sounds like you’d want something like:

“\|(\d+)\|hiddenField\|_EVENTTARGET”

For your first regex, etc.

@Michelle: thanks for the help!

Thanks for your suggestion, Michelle.
i have response like this:

0|hiddenField|__EVENTTARGET||0|hiddenField|__EVENTARGUMENT||0|hiddenField|__LASTFOCUS||2540|hiddenField|__VIEWSTATE|/wEPDwUKMTgyMzU4MzE3OA9kFgJmD2QWAg…|208|hiddenField|__EVENTVALIDATION|/wE…

I’d like to get value “/wEPDwUKMTgyMzU4MzE3OA9kFgJmD2QWAg…” between “__VIEWSTATE|” and “|208”, i tried to use:

.check(regex(“”“|__EVENTARGUMENT|([^”]*)|“”").saveAs(“viewState”))

But it returns blank. what’s wrong with above regex? please give me your idea.

Thanks in advance.

I found out solution for this.
(regex("""|_VIEWSTATE|([\w=/.\d%±.]*)"""

It works.
Thanks,