public CompanyVo queryCompany(String companyNo) {
String jsonBody = "{\"company\": \""+companyNo+"\"}";
String auth = Base64.getEncoder().encodeToString((user+":"+pwd).getBytes());
StringBuilder result = new StringBuilder();
Sap4HanaCompanyVo output;
try{
String sapCompanyPathName = "http/XXXXX";//接口名称
URL url = new URL(sapUrlPath + sapCompanyPathName);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Authorization", "Basic " + auth);
connection.connect();
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);
writer.write(jsonBody);writer.flush();writer.close();
String strRead;
// 返回结果-字节输入流转换成字符输入流,控制台输出字符
InputStream is = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
while ((strRead = reader.readLine()) != null) {
result.append(strRead);
}
logger.info("output result :{}",JSON.toJSONString(result));
output = JSON.parseObject(result.toString(), CompanyVo.class);
reader.close();
connection.disconnect();
}catch (IOException e){
logger.info(" IOException :",e);
throw new RuntimeException("error : " + e);
}
logger.info("output CompanyVo :{}",JSON.toJSONString(output));
return output;
}
05-07
525
01-07
6939