public void getTranslates(){
String host = "https://dm-11.data.aliyun.com";
String path = "/rest/160601/mt/translate.json";
String method = "POST";
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", "APPCODE " + appcode);
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Map<String, String> querys = new HashMap<String, String>();
Map<String, String> bodys = new HashMap<String, String>();
bodys.put("format", "text");
bodys.put("q", translate);
String lauages[] = substring.getSubString(lauage);
String lau1 = lauages[0];
String lau2 = lauages[1];
bodys.put("source", lau1);
bodys.put("target", lau2);
try {
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
String result = EntityUtils.toString(response.getEntity());
JSONObject json = JSONObject.fromObject(result);
String result1 = json.getString("data");
JSONObject json1 = JSONObject.fromObject(result1);
String data = json1.getString("translatedText");
HttpServletResponse response1 = ServletActionContext.getResponse();
response1.setContentType("text/html;charset=utf-8");
PrintWriter out = response1.getWriter();
out.print(data);
System.out.println(data);
} catch (Exception e) {
e.printStackTrace();
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步