Reputation: 628
When a user submits a form that is application/x-www-form-urlencoded and my webpage recieves it it redirects the user to another url. The problem is that the webbrowser doesn't send the application/x-www-form-urlencoded again to the new url.
Is there any way to force the webbrowser to send the application/x-www-form-urlencoded again?
function redirectTo(request, response, site){
try {
response.writeHead('302', {'Location': site});
console.log("redirecting to " + site);
}
} catch(ex) {
// the headers were already sent - we can't redirect them
console.error("Failed to send redirect", ex);
}
response.end();
}
This is the code.
Upvotes: 0
Views: 1895
Reputation: 15463
The code you have posted does not perform a redirect on the server, but rather returns a 302 response, which instructs the browser to redirect based on the new location. When the browser does that, it performs a GET request, not POST. This was a bad implementation in the first browsers, but is still the case because of backward compatibility. There are new response codes introduced (307, 308), which force the browser to preserve the type of the initial request.
The application/x-www-form-urlencoded
is only valid for POST requests, and that's why it is not preserved.
You can read more about this on Wikipedia: http://en.wikipedia.org/wiki/HTTP_302
Upvotes: 6