There is a Java application requesting a page and I wish to block it.
One way I thought to do this was to use sessions or cookies, but I wasn’t sure if the Java URL method could handle them or not.
Is there another way besides using sessions or cookies that I could distinguish requests from this Java application and block it? I know it has a unique Java user-agent header but I wish to be more accurate.
The answer to the headline Question is that the
URL.openXxxmethods do not understand cookies.(If your server is configured to accept session tokens in the request URL itself, the
URL.openXxxmethods won’t get in the way. However, that approach is insecure.)Then we come to the body of your Question.
At this point, I assume that you are talking about blocking requests on the server side. And I should point out that what the “bad guy” client uses to send the request is now immaterial. (It could use
URLor Apache HTTPComponents or it could implement the HTTP protocol stack in assembly code!)So the real question is what options you have for blocking unwanted requests. And the answer is:
In summary, cookies are the best solution, so the “good guy” client application needs to use libraries that are capable of doing cookie management and setting cookies in requests.