I am currently trying to handle some incoming POST requests in Java.
It is working partly so far. I can receive the requests, but I can't seem to extract the parameters and values sent with the request.
Here is my Java code for receiving the requests so far:
public HybridRemoteReceiver() {
try {
System.out.println("running...");
ServerSocket ss = new ServerSocket(3434);
int i = 0;
while (true) {
Socket client = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
if (line.length() == 0)
break;
i++;
}
in.close();
client.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
I am aware that there is a class called HttpServer
, but It's like this class doesn't exist in Java.
I am using java 1.8 in eclipse btw.
However, I can find the classes HttpExchange
and HttpHandler
, but can't seem to make them work.
Basically what I want to achieve, is to receive the data sent with the post request and NOT send anything back to the client.
I really hope anyone can help me out with this.