postman中如何显示返回的base64图片验证码
后端返回的代码
@RestController
public class CaptchaController {
@GetMapping("/captcha")
public User captcha(){
//只是简单的返回了一个base64的字符串,注意下面两个字符串的前面的区别
//String str = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAZAEQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD1LUv7Q/s+X+y/s323jy/tW7y+oznbz0z+OK5C01jxxe6xqOmRp4eE1h5Xmswm2t5i7ht5z0HOQK7quR0dzH468XsuNx+xKuemTGQM+2TXdLdEG3e31pY2M93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EN5K0dxyHWMqVJBxkfL0PXHUZqjrp0O3t44tVtlFvKTiQRHAYYwMryCcnHqAaj8M2xbTZWnQzRGdzayTqC7w8bScjPPJ5/lisE/esPobPkyf8/Mv5L/8AE0UfZLb/AJ94v++BRViJqbIgkjZDkA9x1HuPenUUwIfOMfEylcfxgZU+/t+P61T1ODSdVsmtr/yJ4chtpfkEdwQcg/T1x3rSqnf/APLr/wBfCf1pMGioiiGyitY7uXyUQHzrhjLLL6kg8kdc9vQYpkjySsDFPdPwMvGQR/3yDx+NPX/UW3/XxF/6AtaN3/x5z/8AXNv5VNriMgeRL5Q2gBupmQRq2OuGX+uRVu1tIEcfvXR26ojlVb6HqR36/l0rSrI07/kHH/r4T+a0WswHTWdrJO5uJ3RgcKGk/hx2J5Pf8c0Vq0U+VDsf/9k=";
User user = new User();
user.setId("1");
user.setName(str);
return user;
}
}
将以上代码中上面的一个字符串(即带data:image/jpeg;base64,
)复制到http://www.jsons.cn/img2base64
中然后点击追加img标签
即可将base64字符串转为图片
postman
中通过base64转成图片呢?postman
请求中返回的是base64字符串
然后在Tests
中输入如下代码然后在直接查看即可文章来源:https://www.toymoban.com/news/detail-517339.html
// 将接口返回数据赋值处理
var data = {
response: pm.response.json()
}
// html 模板字符
// 如果base64代码中已包含“data:image/jpg;base64,”,需要在base64代码前面加上,如下:
var template = `<html><img src="data:image/jpg;base64,{{response.name}}" /></html>`;
// 设置 visualizer 数据。传模板并解析对象。
pm.visualizer.set(template, data);
文章来源地址https://www.toymoban.com/news/detail-517339.html
到了这里,关于postman中如何显示返回的base64图片验证码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!