swagger-ui中的security导致401

接口中用了swagger-ui的security安全认证,在service中调用时报401.

在header中添加token信息.

HttpHeaders headers = new HttpHeaders();

      headers.setContentType(MediaType.APPLICATION_JSON);
        String auth = "admin:administrator"; //用户名密码
        String token = Base64.encodeBase64String(auth.getBytes());
        headers.set("Authorization", "Basic " + token);
        String resturil = RestUtils.exchange(url, HttpMethod.GET, headers,String.class);

你可能感兴趣的:(swagger-ui中的security导致401)