Saturday, 22 April 2017

JSoup "HTTP error fetching URL. Status=404" when posting to NodeJS Server

I have a NodeJS server which functions correctly by itself (a user makes a POST request to http://localhost:3000/getGrades and a JSON object is returned containing data). The relevant code (from my server) to my issue is:

app.get('/getGrades', function (req, res) {
var cookies = {};
var username = req.headers.username;
var password = req.headers.password;
etc..........

Now, I am trying to do this POST request from a java program using JSoup:

try{
        Connection.Response res = Jsoup.connect("http://localhost:3000/getGrades")
                .header("username","USERNAME HERE")
                .header("password","PASSWORD HERE")
                .method(Connection.Method.POST)
                .execute();

        System.out.println("Res: " + res.toString());

    }catch (Exception e){System.out.print(e);}
}

However, I get the error:

org.jsoup.HttpStatusException: HTTP error fetching URL. Status=404, 
URL=http://localhost:3000/getGrades
Process finished with exit code 0

Am I going about this incorrectly from the Java client? I looked at similar questions, however, none of them involve JSoup and thus the structure of their POST requests is different. Note: credentials were omitted for privacy!



via Steve

No comments:

Post a Comment