I am trying to send an HTTP request from JS using XMLHttpRequest and receive it in Java server using socket.
I am able to send the request, but the issue with the response is that I am not getting it.
document.getElementById("Update").addEventListener("click", function() {
var xhttp;
var url = "http://192.168.43.1:8081/update";
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
alert(this.responseText);
alert(this.status);
}
};
The status it returns is zero.
Here is my Java code:
try {
String response = "";
response = in.readLine();
System.out.println(response);
requestParser = response.split(" ");
requestType = requestParser[0];
pathFromClient = requestParser[1];
http = requestParser[2];
out.write("HTTP/1.1 200 OK");
out.flush();
socket.shutdownOutput();
socket.close();
} catch (Exception e) {
e.printStackTrace();
}