How can I pull the body out of a POST-запроса ?
I tried using getReader
private Map<String, Object> getBodyFromPostRequest(HttpServletRequest request) throws IOException { Map<String, Object> bodyParameters = new HashMap<>(); Object[] body = request.getReader().lines().toArray(); ... } but in the end, nothing appears in the body array.
forming a request on the client:
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); }