简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM