2

I have a website, with a section that allows a user to log in. Once the user has entered their details and clicked "log in", how would I get that information from the server request to process? I am aware of the "get" method, however, whenever I use this, all of the values from the form are displayed in the URL (including the password).

Here is the function from the server file that deals with the request

function handle(request, response) {
  var url = request.url;
  url = removeQuery(url);
  url = lower(url);
  url = addIndex(url);

  var querystring = require('querystring');
  var params = querystring.parse(require('url').parse(request.url).query);

  if (! valid(url)) return fail(response, NotFound, "Invalid URL");
  if (! safe(url)) return fail(response, NotFound, "Unsafe URL");
  if (! open(url)) return fail(response, NotFound, "URL has been banned");

  var type = findType(url);
  if (type == null) return fail(response, BadType, "File type unsupported");
  if (type == "text/html") type = negotiate(request.headers.accept);
  reply(response, url, type);
}

Basically, how can I get the information out of a form without it being visible in the URL?

2
  • 1
    The browser has to make a POST request. request should have a method to get the body of the request which you can parse. Commented May 24, 2016 at 0:25
  • Thanks. What method would I use to get the body of a request? Commented May 24, 2016 at 0:27

1 Answer 1

2

First stop: change <form action="..." ... to <form method="POST" action="..." ... so the browser will send the form data in a POST.

Next up, request.body has the information you're looking for, though it's not a string, it's a stream, so it's a bit hard to look at. Look at express as a higher-level tool that'll parse these things for you.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I will look into express. I had seen the "post" method mentioned, however I didn't fully understand how I could extract the information I was after
Take a look at the F12 developer tools (e.g. push F12 in your browser) to see the request / response your browser sends. If you're on Windows, Fiddler is a great tool to see it too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.