答案 0 :(得分:2)
是的,此JS函数就是您所需要的:
function(creds) {
var temp = creds.username + ':' + creds.password;
var Base64 = Java.type('java.util.Base64');
var encoded = Base64.getEncoder().encodeToString(temp.bytes);
return 'Basic ' + encoded;
}
然后使用此函数来构建Authorization
标头的值:
* header Authorization = call read('basic-auth.js') { username: 'john', password: 'secret' }
在此处参考文档:https://github.com/intuit/karate#http-basic-authentication-example