// 오른쪽
String TAG = this.getClass().getSimpleName();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
//HttpURLConnection conn = null;
HttpURLConnection conn = null;
try {
URL url = new URL("https://kakaoi-newtone-openapi.kakao.com/v1/recognize");
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Transfer-Encoding", "chunked"); // 파일 전송
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setRequestProperty("X-DSS-Service", "DICTATION");
conn.setRequestProperty("Authorization", "KakaoAK {rest api키값}");
conn.setDoOutput(true);
File wavfile_R = new File(fn1);
//File wavfile_L = new File(fn);
if (wavfile_R.exists()) {
Log.d(TAG, "있다");
} else {
Log.d(TAG, "없다");
}
/*if(wavfile_L.exists()){
Log.d(TAG,"있다");
} else {
Log.d(TAG,"없다");
}*/
byte[] bytes = Files.readAllBytes(wavfile_R.toPath());
// byte[] bytes1 = Files.readAllBytes(wavfile_L.toPath());
Log.d(TAG, "길이==" + bytes.length);
DataOutputStream request = new DataOutputStream(conn.getOutputStream()); // 오른쪽
request.write(bytes);
//request.write(bytes1);
request.flush();
request.close();
//DataOutputStream request1 = new DataOutputStream(conn.getOutputStream()); // 왼 쪽
//request1.write(bytes1);
//request1.flush();
//request1.close();
StringBuilder sb = new StringBuilder();
System.out.println("1222");
System.out.println("con error" + conn.getResponseCode());
System.out.println("Http 오류" + HttpURLConnection.HTTP_OK);
if (conn.getResponseCode() == HttpsURLConnection.HTTP_OK) {
System.out.println("2222");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
sb.append(line).append("\n");
}
in.close();
System.out.println("" + sb.toString());
result = sb.toString();
conn.disconnect();
} else {
Log.d(TAG, "여기");
System.out.println(conn.getResponseMessage());
result = conn.getResponseCode() + conn.getResponseMessage();
}
} catch (Exception e) {
Log.d(TAG, "저기");
System.out.println(e.toString());
}
} else {
System.out.println("222");
// 왼쪽
String TAG1 = this.getClass().getSimpleName();
StrictMode.ThreadPolicy policy1 = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy1);
HttpURLConnection conn1 = null;
try {
URL url = new URL("https://kakaoi-newtone-openapi.kakao.com/v1/recognize");
conn1 = (HttpURLConnection) url.openConnection();
conn1.setRequestMethod("GET");
conn1.setRequestProperty("Transfer-Encoding", "chunked"); // 파일 전송
conn1.setRequestProperty("Content-Type", "application/octet-stream");
conn1.setRequestProperty("X-DSS-Service", "DICTATION");
conn1.setRequestProperty("Authorization", "KakaoAK {rest api키값}");
conn1.setDoOutput(true);
File wavfile_L = new File(fn);
if (wavfile_L.exists()) {
Log.d(TAG1, "있다");
} else {
Log.d(TAG1, "없다");
}
byte[] bytes1 = Files.readAllBytes(wavfile_L.toPath());
Log.d(TAG1, "길이==" + bytes1.length);
DataOutputStream request = new DataOutputStream(conn1.getOutputStream()); // 오른쪽
request.write(bytes1);
request.flush();
request.close();
StringBuilder sb1 = new StringBuilder();
System.out.println("1333");
System.out.println("conn 에러" + conn1.getResponseCode()); // 키값문제
System.out.println("http 오류" + HttpURLConnection.HTTP_OK);
if (conn1.getResponseCode() == HttpsURLConnection.HTTP_OK) {
System.out.println("3333");
BufferedReader in = new BufferedReader(new InputStreamReader(conn1.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
sb1.append(line).append("\n");
}
in.close();
System.out.println("" + sb1.toString());
result = sb1.toString();
conn1.disconnect();
} else {
Log.d(TAG1, "여기");
System.out.println(conn1.getResponseMessage());
result = conn1.getResponseCode() + conn1.getResponseMessage();
}
} catch (Exception e) {
Log.d(TAG1, "저기");
System.out.println(e.toString());
}
}[quote="jongdalab, post:1, topic:115747, full:true"]
위사진은 vue.js(java script)로 카카오톡 링크공유(커스텀)으로 구현을 한 것인데(동적으로 이미지표출),
안드로이드로도 구현이 가능한지 궁금합니다.
api문서를 보니 이미지 args는 보낼수 없는 것 같아서 여쭈어봅닌다.
[/quote]
conn.getResponseCode() 안드로이드 개발중에 저 부분이 401에러가 계속 뜨는데 어떻게 처리 하나요 ??