下面是贴出来的请求代码。 麻烦大佬给看看嗯? 我有 15 台集群,每台都这么调用的。 是不是我需要在is = conn.getInputStream(); 这个地方判断下图片是否生成???
String basePath = "";
HttpsURLConnection conn = null;
OutputStream outputStream = null;
InputStream is = null;
OutputStream os = null;
try {
TrustManager[] tm = {newMyX509TrustManager()};
SSLContext sslContext = SSLContextgetInstance("SSL", "SunJSSE";
sslContext.init(null, tm, new java.security.SecureRandom());
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url = newURL(requestUrl;
conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(ssf;
conn.setDoOutput(true;
conn.setDoInput(true;
conn.setUseCaches(false;
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod(requestMethod;
outputStream = conn.getOutputStream();
outputStream.write(outputStr.getBytes("UTF-8");
outputStream.close();
String path2 = request.getSession().getServletContext().getRealPath("/";
String path = path2.replace("\\", "/") + "SmallProgram";
File file = newFile(path;
if (!file.exists()) {
file.mkdirs();
}
Date now = newDate();
SimpleDateFormat dateFormat = newSimpleDateFormat("yyyyMMddHHmmssSSS";
String name = dateFormat.format(now);
name = "/" + name + CommonUtilnumber + ".png";
String path1 = path + name;
basePath = request.getScheme() + "://" + request.getServerName() + request.getContextPath() + "/SmallProgram" + name;
CommonUtilsetNumber(number++;
is = conn.getInputStream();
os = newFileOutputStream(path1;
byte[] bs = new byte1024;
String resultInfo = null;
int len;
while ((len = isread(bs)) != -) {
os.write(bs, , len);
os.flush();
resultInfo = newString(bs, "UTF-8";
}
booleanbool = false;
if (resultInfo == null || resultInfo.contains("errcode")) {
bool = true;
}
if (bool) {
logger.error("获取小程序码异常,异常信息:" + resultInfo);
returnnull;
}
os.flush();
os.close();
isclose();
conn.disconnect();
} catch (ConnectException ce) {
Systemout.println("连接超时:{}");
basePath = "";
} catch (Exception e) {
Systemout.println("https请求异常:{}");
basePath = "";
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
if (is != null) {
isclose();
}
if (os != null) {
os.close();
}
if (conn != null) {
conn.disconnect();
}
} catch (IOException e) {
Systemout.println("https请求异常:{}");
}
}
return basePath;
不懂java,不好意思
求大佬帮忙看看。
is = conn.getInputStream()sh
是不是要判断下 is 是否读取到呢? 怎么判断是否读取到呢???