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

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;
}
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (3 comments)

0 answers

Sign up to answer this question »