Php SOAPUIGroovy脚本返回异常:StringIndexOutOfBoundsException(-2)我不明白为什么

Php SOAPUIGroovy脚本返回异常:StringIndexOutOfBoundsException(-2)我不明白为什么,php,soap,groovy,Php,Soap,Groovy,我目前正在使用SoapUI,我对此有点不在行。我正在尝试使用一个脚本从HTTP头检索一个设置Cookie PHP会话ID,但是我遇到了上面的异常。不管怎样,以下是我的脚本代码: def header = testRunner.testCase.getTestStepByName("Authenticate").httpRequest.response.responseHeaders["Set-Cookie"] header = header.toString() start = header.i

我目前正在使用SoapUI,我对此有点不在行。我正在尝试使用一个脚本从HTTP头检索一个设置Cookie PHP会话ID,但是我遇到了上面的异常。不管怎样,以下是我的脚本代码:

def header = testRunner.testCase.getTestStepByName("Authenticate").httpRequest.response.responseHeaders["Set-Cookie"]
header = header.toString()
start = header.indexOf("PHPSESSID=")
end = header.indexOf("; Path=")
sessionIdValue= header.substring(start, end)
testRunner.testCase.getTestStepByName("FavouriteLocations").setPropertyValue("session_key",sessionIdValue)

如果您有任何意见,我将不胜感激。

您有一个标题变量,其中包含哪些内容?我怀疑标题中没有“PHPSESSID=”或“Path=”。这就是为什么在header.substring(开始、结束)上获得StringindexOutOfBoundsException。在groovy脚本上打印带有log.info头的头内容。试试这个:HTH。最后它成功了,很抱歉回复太晚。谢谢你的努力!