Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 未经授权的401-Spring启动服务_Spring Boot_Docker_Http - Fatal编程技术网

Spring boot 未经授权的401-Spring启动服务

Spring boot 未经授权的401-Spring启动服务,spring-boot,docker,http,Spring Boot,Docker,Http,我有一个spring引导服务调用另一个spring引导服务 这两个服务都部署到docker容器中 当第一个服务调用第二个服务时,第二个服务得到401响应。当我用邮递员做同样的请求时,我得到了一个有效的回复 假设我通过邮递员和服务本身使用凭证 你知道为什么会这样吗?是否存在与docker部署相关的问题 用于调用第二个服务的代码 try { urlStr = licenseRequest.getString(LicenseRequest.URL); logger.in

我有一个spring引导服务调用另一个spring引导服务

这两个服务都部署到docker容器中

当第一个服务调用第二个服务时,第二个服务得到401响应。当我用邮递员做同样的请求时,我得到了一个有效的回复

假设我通过邮递员和服务本身使用凭证

你知道为什么会这样吗?是否存在与docker部署相关的问题

用于调用第二个服务的代码

try {
        urlStr = licenseRequest.getString(LicenseRequest.URL);
        logger.info("URL: "+ urlStr);
        
        URL url = new URL(urlStr);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("POST");
        
        con.setRequestProperty("Content-Type", "application/json");
        
        // auth 
        String authStrEncoded = Base64Utils.encodeToString((username + ":" + password).getBytes());
        con.setRequestProperty("Authorization", "Basic " + authStrEncoded);
        
        if (!licenseRequest.isNull(LicenseRequest.BODY))
        {
            String body = licenseRequest.getString(LicenseRequest.BODY);
            con.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream (
                con.getOutputStream());
            wr.write(body.getBytes());
            wr.close();
        }
            //Get Response  
            InputStream is = con.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            StringBuilder response = new StringBuilder(); // or StringBuffer if Java version 5+
            String line;
            while ((line = rd.readLine()) != null) {
              response.append(line);
              response.append('\r');
            }
            rd.close();
            return response.toString();
        
    } 

邮递员请求中的授权标头与服务中的授权标头是否相同?如果您收到401,这意味着服务器可以与另一台服务器通信,这与docker无关,它与authYes有关,授权标头完全相同