Search code examples
javaservletsweb-applicationshttp-status-code-403

Stopping java web application from returning Error 403: Forbidden


I am writing a program that should run on a webserver in Java that is used to store data from http post requests in a database.

When I try to send a http post request to it, my server always returns: "Error 403: Forbidden".

Here is my web application:

@WebServlet("/pushData")
public class PushDataServlet extends HttpServlet
{
    @Override
    protected void doPost( final HttpServletRequest request, final HttpServletResponse response )
    throws IOException
    {
    try {
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = request.getReader();

        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        String string = builder.toString();

        //send data to database

        response.getWriter().write(string);
} catch (Exception e) {
    response.getWriter().write(e.toString());
}

How do I stop the server from returning that error? Can I allow only certain senders to access the server?


Solution

  • Solved it on my own. Was a problem with my network environment.