I'm trying to learn a bit of Java's HTTP server, I have a simple setup, on a PHP server I have an input field where I upload a File with POST. I was wondering if it is possible to get that file in the Java server.
My current setup is the most simple one, on my main I have:
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); server.createContext("/test", new MyHandler()); server.start(); I can't find anything showing what to do from here on to get the File, I tried looking through everything given by HttpExchange.
I know that I can send a POST request but i don't know how to listen to one or even if it is possible to get the file from it.
MyHandlerclass needs to read the content of the POST request body, then process that content. To handle file uploads, the client would send content asmultipart/form-data, so do some research and lookup and learn what that means for the POST content, e.g. What does enctype='multipart/form-data' mean?.<input type="file">element, then you didn't tell the form to post asmultipart/form-data. Check 2nd link up top: How does HTTP file upload work?. I.e. please do your research on how to do file uploads.