Trying to create a POST request with Apache
+3
−0
I have tried many different ways to do this with apache but the server seems to not be receiving the data. Stacktraces are not being printed so I can only assume I have the request set up wrong for the server to receive the data. My current code looks like this:
try {
fixUntrustCertificate();
url = new URL("https://panel.<address>.com/api/v1/server/send_command?
token=" + apikey + "&id=6");
CloseableHttpClient client = HttpClients.createDefault();
//POST to be executed
HttpPost post = new HttpPost("https://panel.
<address>.com/api/v1/server/send_command?token=" + apikey + "&id=6");
//data to send in POST
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("command", command));
//command is a console command such as "ping", which would warrant
//"pong" in response from the server.
//Headers
post.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64;
x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192
Safari/537.36");
post.setHeader("Accept", "text/html");
post.setHeader("Host", "panel.<address>.com");
post.setHeader("Content-Type", "multipart/form-data");
//Entity to send
post.setEntity(new UrlEncodedFormEntity(params));
//POST execution
client.execute(post);
client.close();
} catch (MalformedURLException e) {
String stack = ExceptionUtils.getStackTrace(e);
stackTrace = stack;
} catch (IOException e) {
String stack = ExceptionUtils.getStackTrace(e);
stackTrace = stack;
} catch (JSONException e) {
String stack = ExceptionUtils.getStackTrace(e);
stackTrace = stack;
} catch (NoSuchAlgorithmException e) {
String stack = ExceptionUtils.getStackTrace(e);
stackTrace = stack;
} catch (KeyManagementException e) {
String stack = ExceptionUtils.getStackTrace(e);
stackTrace = stack;
}
1 comment thread