Spring boot 未经授权的401-Spring启动服务
我有一个spring引导服务调用另一个spring引导服务 这两个服务都部署到docker容器中 当第一个服务调用第二个服务时,第二个服务得到401响应。当我用邮递员做同样的请求时,我得到了一个有效的回复 假设我通过邮递员和服务本身使用凭证 你知道为什么会这样吗?是否存在与docker部署相关的问题 用于调用第二个服务的代码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
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有关,授权标头完全相同