public String APIExamCaptchaImage(String key) {
String clientId = "ㅇㅇ";// 애플리케이션 클라이언트 아이디값";
String clientSecret = "ㅇㅇ";// 애플리케이션 클라이언트 시크릿값";
String tempname = null;
StringBuffer response = null;
try {
//String key2 = key; // https://openapi.naver.com/v1/captcha/nkey 호출로 받은 키값
String apiURL = "https://openapi.naver.com/v1/captcha/ncaptcha.bin?key=" + key;</p><p><span style="white-space:pre"> URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("X-Naver-Client-Id", clientId);
con.setRequestProperty("X-Naver-Client-Secret", clientSecret);
int responseCode = con.getResponseCode();
BufferedReader br;
if (responseCode == 200) { // 정상 호출
InputStream is = con.getInputStream();
int read = 0;
byte[] bytes = new byte[1024];
// 랜덤한 이름으로 파일 생성
tempname = Long.valueOf(new Date().getTime()).toString();
File f = new File("tempname" + ".jpg");
f.createNewFile();
OutputStream outputStream = new FileOutputStream(f);
while ((read = is.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
is.close();
} else { // 에러 발생
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
String inputLine;
response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
}
} catch (Exception e) {
System.out.println(e);
}
//return tempname;
return tempname;
}
<%
String contextRoot = request.getContextPath();
Key m= new Key();
String key2 = m.APIExamCaptchaNkey();
key2 = key2.substring(8,24);
String tempname = m.APIExamCaptchaImage(key2);
tempname = String.format(""%s.jpg"",tempname);
%>
<div class="container">
<h1>index page</h1>
<%=key2 %><br>
<%=tempname %><br>
<img src=<%=tempname %>>
</div>
캡챠 이미지 다운 잘 됨?
차라리 리캡챠를...
그냥 자바 콘솔로 실행하면 이미지 다운 잘 되는데 jsp 경유해서 하면 저 오류뜸