I am not looking to do anything complicated: I'm trying to do a bare-bones as-simple-as-possible transmission from client to server.
I know the way to do that with HTTP clients/servers is to use POST.
I've been trying to get even just a simple POST request to work for 6-7 hours now and have gotten nowhere. So I figured it was time to stop trying to figure it out on my own and post a question here: What is the simplest way to transmit a value from an HTTP client to an HTTP server coded in Java using a POST request?
I think I understand how to send data from the client, but I can't find anywhere that explains how to receive it at the server.
This is what I used in my server program (worked through a tutorial) just to test with a GET request from the client (it worked):
public static void main(String args[]) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8000),0);
server.createContext("/test", new testHandler());
server.setExecutor(null);
server.start();
}
static class testHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
String test = "Hello World!";
t.sendResponseHeaders(200,test.length());
OutputStream stream = t.getResponseBody();
stream.write(test.getBytes());
stream.close();
}
How would I modify the above code to accommodate a POST request? (i.e. accept a value from the client).