Java 在Postman环境中限制标头中返回的字符

Java 在Postman环境中限制标头中返回的字符,java,postman,postman-collection-runner,Java,Postman,Postman Collection Runner,我正在使用一个API集,该API集要求下拉会话密钥,并在授权标头中用于后续的服务调用。要添加到标题的值为X-CardConnect-SessionKey请参见下面的示例。前20位数字,分号前面的所有数字,一旦获得,就需要包含在以后对服务的调用中 这就是我得到的--> 这就是我需要的: X-CardConnect-SessionKey →9ffcd7dc737f4b9fbdccb299b9c55f4b 在Postman中,我使用以下方法将会话键值解析到我的环境中: var data = res

我正在使用一个API集,该API集要求下拉会话密钥,并在授权标头中用于后续的服务调用。要添加到标题的值为X-CardConnect-SessionKey请参见下面的示例。前20位数字,分号前面的所有数字,一旦获得,就需要包含在以后对服务的调用中

这就是我得到的-->

这就是我需要的:

X-CardConnect-SessionKey →9ffcd7dc737f4b9fbdccb299b9c55f4b
在Postman中,我使用以下方法将会话键值解析到我的环境中:

var data = responseHeaders
postman.setEnvironmentVariable ("X-CardConnect-SessionKey", data["X-
CardConnect-SessionKey"])
当然,当我只需要前20位数字时,完整的字符串就会插入到环境中。是否有办法限制字符限制,以便只返回前20位

谢谢

您可以使用本机JS或使用其中一个Lodash函数查看值

var data = "9ffcd7dc737f4b9fbdccb299b9c55f4b;expires=2017-12-
28T20:54:19.652Z"

postman.setEnvironmentVariable("test", data.split(';',1)); 
或者是你需要的东西:

var data = responseHeaders
postman.setEnvironmentVariable("X-CardConnect-SessionKey", data.X-
CardConnect-SessionKey.split(';',1))

能够解决以下问题:

const data = responseHeaders;
postman.setEnvironmentVariable ("X-CardConnect-SessionKey", data["X-CardConnect-SessionKey"]); 
const sessionheader = data["X-CardConnect-SessionKey"];
postman.setEnvironmentVariable ("X-CardConnect-SessionKey",  sessionheader.substring(0, 32));

丹尼。我来试一试。@RobertCowie试一下,看看它是否适用于你不需要的东西,你没有机会从内存中测试出来,所以第一次可能不起作用。酷,你需要创建所有的变量吗?你可以在一行中完成所有这些。查看作为新版本一部分的api中的
pm.response.headers()
。您正在使用的语法是旧样式,很快将被删除。
const data = responseHeaders;
postman.setEnvironmentVariable ("X-CardConnect-SessionKey", data["X-CardConnect-SessionKey"]); 
const sessionheader = data["X-CardConnect-SessionKey"];
postman.setEnvironmentVariable ("X-CardConnect-SessionKey",  sessionheader.substring(0, 32));