Reusing data from the HTML code of a webpage (e.g. session id) for subsequent requests
This script shows how to read some data from the HTML of a page and the use this data in subsequent requests.
Sample Code
' ===============================================================
' Webserver Stress Tool V7 *** Sample Script for Reusing a Token
' ===============================================================
' Requires Webserver Stress Tool 7.0.2 or later
Sub OnBeforeClick
if data.clickcount=0 then data.url="https://walldorf.paessler.com" end if
if data.clickcount=1 then data.url="https://walldorf.paessler.com/?test="+data.token end if
data.log="Preparing click #"+inttostr(data.clickcount+1)+" of user #"+inttostr(data.usernumber+1)
end Sub
Sub OnAfterClick
data.log=""
end sub
Sub OnbeforeRequest
data.log=""
end sub
Sub OnAfterRequest
if data.clickcount=0 then 'we only look in the HTML of the first click for our tags
if data.requestcount=0 then 'we only look in the HTML of the first request of the first click for our tags
tagbefore="<title>"
tagafter="</title>" 'our tag/token delimiters
if pos(tagbefore,request.html)>0 then
if pos(tagafter,request.html)>0 then
tagbegin=pos(tagbefore,request.html)+length(tagbefore)
taglength=pos(tagafter,request.html)-tagbegin
mytag=copy(request.html,tagbegin,taglength)
data.log="FOUND TOKEN: '"+mytag+"'"
data.token=mytag
else
data.log="Closing Token not found ("+tagafter+") in request number "+inttostr(data.requestcount)+" with resultcode "+inttostr(request.resultcode)+" ("+request.result+")"
end if
else
data.log="Opening Token not found ("+tagbefore+") in request number "+inttostr(data.requestcount)+" with resultcode "+inttostr(request.resultcode)+" ("+request.result+")"
end if
end if
end if
end sub
Add comment