限制在邮递员环境中的标题中返回的字符

时间:2017-12-28 20:54:20

标签: java postman postman-collection-runner

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

Postman Image

这就是我得到的 - >

let texture = SCNMaterial()
var newImage: UIImage?
if let textureImage = UIImage(named: "rgb image with only gray") {
    UIGraphicsBeginImageContext(textureImage.size)
    let width = textureImage.size.width
    let height = textureImage.size.height
    textureImage.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
    newImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
}
texture.diffuse.contents = newImage

这就是我需要的:

X-CardConnect-SessionKey →9ffcd7dc737f4b9fbdccb299b9c55f4b;expires=2017-12-28T20:54:19.652Z

在Postman中我使用以下内容将Session Key值解析到我的环境中:

X-CardConnect-SessionKey →9ffcd7dc737f4b9fbdccb299b9c55f4b

当然,当我只需要前20位时,完整的字符串会插入到环境中。有没有办法限制字符限制,以便只返回前20位数字?

谢谢!

2 个答案:

答案 0 :(得分:0)

您可以使用本机JS split或使用其中一个Lodash _.split()函数来查看值。

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))

答案 1 :(得分:0)

能够解决以下问题:

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

相关问题