I am learning Vue at the moment, and is trying to send some post variable onto a simple Java servlet. However, all the call for getParameter come out as NULL when I try to access them.
I send the post request with the following code:
let formData = new FormData();
formData.append('brukernavn',this.skjema.brukernavn);
formData.append('passord',this.skjema.passord);
console.log(formData);
axios.post('/BoardgamesRegister/ajax/login',formData)
.then(function(response){
console.log(response);
})
.catch(function(error){
});
However, when I try to access these variable on the serverside with this code, I just get NULL as a value.
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
System.out.println(req.getParameter("brukernavn"));
System.out.println(req.getParameter("passord"));
this.executeRequest(req,res,pw,null);
}
The thing is, if I attempt to add a GET parameter to the URL for the call, that value gets picked up correctly by the getParameter method. So it seems that my POST variables somehow get lost to the request. Is it something wrong with my Vue code or is it something on the serverside? I tried to Enumerate through the request parameters, and only the get parameters showed up, not the post ones.
It seems to be an issue in the Java Servlet, because when I tried to send the request to a PHP script instead, the POST paramentere were picked up correctly.
The comment from @Tim was not the issue, but it did indeed lead on the right path. I somehow missed that Axios encrypt post call parameters into JSON automatically. So in a normal POST request, getParameter will indeed work, but not here. So now, I simply need to find a way to stop Axios from converting into JSON.