자바 메인메소드에서 테스트중인데 404에러가 발생합니다… 도저히 이유를 모르겠습니다.
public class translator {
public static void main(String[] args) {
String apikey="저의 REST API키 넣었습니다.";
try{
String text=URLEncoder.encode("안녕","UTF-8");
String postParams="src_lang=kr&target_lang=en&query="+text;
String apiURL="https://kapi.kakao.com/v1/translation/translate"+postParams;
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
String userCredentials=apikey;
String basicAuth ="KakaoAK "+userCredentials;
con.setRequestProperty("Authorization", basicAuth);
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("charset", "utf-8");
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
int responseCode=con.getResponseCode();
System.out.println("responseCode="+responseCode);
BufferedReader br;
if(responseCode==200){
br= new BufferedReader(new InputStreamReader(con.getInputStream()));
}
else{
br= new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer res= new StringBuffer();
while((inputLine = br.readLine())!=null){
res.append(inputLine);
}
br.close();
System.out.println("응답결과="+res.toString());
}
catch(Exception e)
{
System.out.println("오류발생");
System.out.println(e);
// TODO Auto-generated method stub
}
}
}
발생에러 : responseCode=404
응답결과={“msg”:“Not Found”,“code”:-404}