private void translate(String from, String to, String text) throws IOException {标签:body,翻译,String,text,RequestBody,application,json,机械 From: https://www.cnblogs.com/LiuLyuancn/p/17904209.html
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"from\":\"" + from + "\",\"to\":\"" + to + "\",\"q\":\"" + text + "\"}");
Request request = new Request.Builder()
.url("https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1?access_token=XXX")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.build();
Response response = HTTP_CLIENT.newCall(request).execute();
String translation = parseTranslation(response.body().string());
outputField.setText(translation);
}