Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String getURL(String url) {
- String result = "";
- try {
- URL u = new URL(url);
- // создаём соединение
- HttpURLConnection urlConnection = (HttpURLConnection) u.openConnection();
- String data = "format=plain&lang=en-ru";
- String key = "YOUR_KEY_HERE";
- String text_to_translate = "Hello & Goodbye";
- text_to_translate = URLEncoder.encode(text_to_translate, "UTF-8");
- // нужно добавить в к строке data поля key, text_to_translate
- urlConnection.setDoOutput(true); // setting POST method
- OutputStream out = urlConnection.getOutputStream();
- out.write(data.getBytes());
- // создаём потом ввода и читаем ответ сервера
- InputStream in = urlConnection.getInputStream();
- Scanner sc = new Scanner(in);
- // 2) считать содержимое ответа от сервера
- // записать в переменную result
- urlConnection.disconnect();
- } catch (IOException e ) {}
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement