When I sent the following request to my program, the body gets lost:
GET http://localhost:4567/contacts/get-all
Authorization : test
Content-Type : text/plain
Hello
Java Code
public class Test {
public static void main(String[] args) {
Spark.get("contacts/get-all", (request, response) -> {
checkForAuth(request);
if (request != null) {
System.out.println(request.body());
}
return "Success";
});
}
protected static void checkForAuth(Request request) {
if (request != null) {
String authorization = request.headers("Authorization");
System.out.println(authorization);
if ("test".equals(authorization))
return;
}
throw new Error("Not Authorized.");
}
}
I expected the sysout to print Hello, but it only prints test (authorization header).
What am I doing wrong?