in src/main/java/software/aws/chatops_lex_api/resource/Util.java [105:145]
private static String post(String url, Map<String,String> headers, String body) throws Exception {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//Request method
con.setRequestMethod("POST");
//Request header
con.setRequestProperty("User-Agent", Util.USER_AGENT);
for(String key: headers.keySet()) {
con.setRequestProperty(key, headers.get(key));
}
logger.info("\nSending HTTP 'POST' to URL: " + url);
//send output
con.setDoOutput(true);
try(OutputStream os = con.getOutputStream()) {
byte[] input = body.getBytes("utf-8");
os.write(input, 0, input.length);
}
int responseCode = con.getResponseCode();
logger.info("Response Code : " + responseCode);
StringBuffer response = new StringBuffer();
try( BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream())) ){
String inputLine;
while ((inputLine = in.readLine()) != null) {
if(response.length()>=MAX_FILE_SIZE){
throw new RuntimeException("Response is too big");
}
if( inputLine.length() <= MAX_FILE_SIZE ){
response.append(inputLine);
}else{
throw new IllegalArgumentException("Response is too big");
}
}
}
con.disconnect();
return response.toString();
}