需要将API成功响应复制到邮递员的剪贴板



我必须将API响应复制到剪贴板(ctrl+c(。我试着通过document.executeCommand在post-man测试部分完成。但我得到的文件是没有定义的错误。

有其他方法可以满足我的要求吗。

编辑:我已经完成了。

试试这个:

let template =
`
<textarea id='copy' style='width:35%'></textarea>
<script>
pm.getData(function (error, data)
{
var node = document.getElementById('copy');
node.textContent = data.response;
var selection = document.getSelection();
selection.removeAllRanges();
node.select();
document.execCommand('copy');
selection.removeAllRanges();
document.getElementById('copy').textContent = 'Response copied to clipboard!';
});
</script>
`;
pm.visualizer.set(template, {
response: responseBody
});

上一个答案

您可以以三重点击(突出显示(的格式将其打印到控制台,使其复制速度更快。我在我的一个收藏中使用了这种技巧。

我的示例响应是JSON,但我想要的部分是嵌套的,所以我使用以下日志语句:

console.info(ζ.name + " Results:nr", ζ.results.data[0]);

其中ζ.results.data[0]部分是一个方便的、可点击三次的JSON字符串。

最新更新