curl -user username:password url转换http发送
文章目录
0x00.背景
博主最近打算用spring boot + oauth2 + jwt构建一套sso单点登录系统,查看资料的时候,很多例子给的都是curl -user username:password url这种方式的测试,博主打算转换成postman发起请求,查了些资料才知道怎么改写
0x01.crul请求数据
- 请求脚本
curl --request POST
--user android-client:android-client
--url http://localhost:8090/oauth/token
--header 'Content-Type: application/x-www-form-urlencoded'
--data 'username=customer_one&grant_type=password&password=customer_one'- 响应结果

0x02.转换成Postman
--user android-client:android-client:对应的Authorization。

--data:对应请求Body。

- 响应结果

0x03.Authorization如何转换?
- Basic后面字符串是
Base64.encode("user:pwd")后的。
@Test
public void encodeAuthTest() {
String token = "android-client:android-client";
Base64.Encoder encoder = Base64.getEncoder();
byte[] bytes = encoder.encode(token.getBytes());
System.out.println(new String(bytes)); //YW5kcm9pZC1jbGllbnQ6YW5kcm9pZC1jbGllbnQ=
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论