PostMan添加Authorization验证
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9bf2e8b657809d74093017bd31fcc843.png#pic_center)
HttpClient调用三方接口设置Header
String url ="URL路径";
Map<String, String> prarms = new HashMap<>();
prarms.put("userName","案例");
prarms.put("age", "18");
String jsonPrarms = JSON.toJSONString(prarms);
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(url);
String encoding = DatatypeConverter.printBase64Binary("username:password".getBytes("UTF-8"));
httpPost.setHeader("Authorization", "Basic " + encoding);
HttpEntity entityParam = new StringEntity(jsonPrarms,ContentType.create("application/json", "UTF-8"));
httpPost.setEntity(entityParam);
HttpResponse response = httpClient.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int responseCode = statusLine.getStatusCode();
if (responseCode == 200) {
HttpEntity entity = response.getEntity();
InputStream input = entity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(input,"utf-8"));
String str1 = br.readLine();
System.out.println("服务器的响应是:" + str1);
br.close();
input.close();
} else {
System.out.println("响应失败");
}