Каким образом можно вытащить body
из POST-запроса
.
Попробовал через getReader
private Map<String, Object> getBodyFromPostRequest(HttpServletRequest request) throws IOException {
Map<String, Object> bodyParameters = new HashMap<>();
Object[] body = request.getReader().lines().toArray();
...
}
но в итоге в массиве body
ничего не оказывается.
формирование запроса на клиенте:
function signUpAction(){
var xhr;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
var log = document.getElementById('login').value;
var pas = document.getElementById('password').value;
xhr.open('POST', '/reg', true);
var body = 'login=' + encodeURIComponent(log) +
'&password=' + encodeURIComponent(pas);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.status != 200) {
alert( xhr.status + ': ' + xhr.statusText );
} else {
console.log( xhr.responseText );
}
};
xhr.send(body);
}