This question already has answers here:
How to process POST data in Node.js?
(30 answers)
Closed 8 years ago.
I'm wondering how to get an array that contains all parameters sent in a HTTP request.
If I read the doc: http://expressjs.com/4x/api.html#req.params
I can see that using req.params and req.query, params will be linked to the route parameters and query to the GET parameters. But how can I log the post parameters? The req.param() method requires an argument and doesn't returns an array if I don't provide one. Since all POST parameters must be used through req.param(), there is no way to log them for now. Or am I missing something?
My goal is to efficiently log all parameters to debug easily the application during development, let me know if you have a better way.
You're looking for req.body, which contains the parsed POST body. (assuming you have middleware that parses it)
Related
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 3 months ago.
This is a basic registration form.
script.js performs input checking.
express.js sends and receives data from mongodb.
What I need to do is send input values (such as username.value) after input checking from script.js to express.js. How do I do it?
things to keep in mind this is an assignment and I cannot use jQuery, React etc. just HTML, CSS, JS, Express and mongodb
You could use the fetch API to do a POST request and capture it with express.
The FormData API works well for getting the data out of a form.
Example:
fetch(/* POST endpoint */, {
body: new FormData(/* form element */),
method: 'POST'
});
This question already has answers here:
Sending PHP GET data to server using Html links
(2 answers)
Closed 4 years ago.
I know that requests placed by jQuery $.get() can include an optional parameter for additional data. I was wondering if there was any way to pass that information through requests that come about by clicking an link, or relocation the windows location.
Yes, you can use a Query String.
Excerpt:
Typical URL containing a query string is as follows:
http://example.com/over/there?name=ferret
When a server receives a request for such a page, it may run a program, passing the query string, which in this case is, name=ferret unchanged, to the program. The question mark is used as a separator, and is not part of the query string.
So your anchor could be:
My Link
or
My Link
or
My Link
Be aware that you can get caching issues by links/get requests.
The only way to pass data through a link as the page is visited is to use URL Parameters/Query Strings.
This question already has answers here:
How to send an email from JavaScript
(20 answers)
Closed 4 years ago.
I have a problem. I want to put a contact form on the page, but I do not know how to do it in the Vue. I wanted to do it normally as jquery, php, but it does not work in Vue. Does anyone have an idea what I can do?
Vue is a View (hence the name) library, meant for describing your View layer i.e. how your application looks. Such logic as sending an email would for one be dependent on Javascript itself and not on Vue.
However it is not possible to send an email from Javascript in the browser. Instead you'd need to build a backend which can send an email for you, or you could call the user's email client, both described here.
You would ideally send email data (to, message body - html escaped of course) as a request to a backend end point and send from there. You can use Vue's HTTP resource to send the request: https://github.com/pagekit/vue-resource
But sending an email directly from Vue isn't possible.
This question already has answers here:
When do you use POST and when do you use GET?
(27 answers)
Closed 6 years ago.
We can accomplish the same thing by doing:
localhost:3000/endpoint?var1=val1&var2=val2
That we can do by using POST with a JSON body.
So why should anyone use PUT/POST/PATCH if they can get the same goals by using url params? Even with auth, instead of header, you can send the information of the auth token back and forth by using a parameter?
one reason is that GET parameters have to be URL-encoded.
then there are limitations of URL length documented in RFC I think.
This will make it difficult when transfering large data (e.g. file uploads,...)
additionally, developers may want to hide some informations from the user, to prevent users to bookmark a page with all these parameters...
Definitely NO reason for POST args is security on the transport layer. in both cases the data are plain text in HTTP, and both (also the URL) are encoded end-to-end when using a secure HTTPS connection.
It is more secure, because your data is encrypted and sent in the header of the request.
This question already has answers here:
Passing "#" hash symbol in request parameter of url not working in Firefox
(3 answers)
Closed 6 years ago.
I have a problem. I'm working with Elixir Phoenix and React.JS. I have a Token that is used to verify the user. This Token also has hashtags in it so when I send a request to verify it, it is being sent without the hash symbols and what comes after them which makes my request to fail. How can I solve this issue? For some reason I don't have that problem when I use fetch with React Native, but here I do. I tried many variations as you can see in the image.
The hash and anything after it will not be sent by browsers in a request.
You should encode the token so that the hash is escaped.
fetch('http://localhost:4000/api/users/'+encodeURIComponent(accesstoken), {