Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Q&A Trying to create a POST request with Apache

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...

0 answers  ·  posted 3y ago by cuzzo‭  ·  edited 3y ago by Alexei‭

#3: Post edited by user avatar Alexei‭ · 2021-03-16T06:53:04Z (about 3 years ago)
added relevant tags
  • 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;
  • }
  • []()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;
  • }
#2: Post edited by user avatar cuzzo‭ · 2021-03-16T02:09:00Z (about 3 years ago)
  • 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;
  • }
  • 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: Initial revision by user avatar cuzzo‭ · 2021-03-16T02:08:14Z (about 3 years ago)
Trying to create a POST request with Apache
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;
    }