public static String excutePost(String targetURL, String urlParameters)
{
URL url;
HttpURLConnection connection = null;
try {
//Create connection
url = new URL(targetURL);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// connection.setRequestProperty("chat_id", "***");
// connection.setRequestProperty("text", "Hello, world");
Map<String,Object> params = new LinkedHashMap<>();
params.put("chat_id", "***");
params.put("text", "Hello, world");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
return response.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if(connection != null) {
connection.disconnect();
}
}
}
Не могу понять как передать параметры post запросом телеграмму. Параметры text и chat_id
Помогите новичку