Regardless of which web-site application has been developed, the beginner's first reference to the starting hand, eight or nine is the value of Get/post Request. However, in the world of node. js + Express, it seems that everyone is a master, born to use, never seen someone write.
This should be the opening of the Web Service, in the Client and Server interaction, the browser out of the Get/post Request will be the value of server-side, the common application is the page with the POST method sent out of the form, or the web Query Strings (ex:page?page=3&id=5) on the Address column. Then our web site is programmed to parse these parameters and get the information from the user.
Obtain the Get Request Query Strings:
GET/Test?Name=Fred&Tel=0926xxx572Appget ( '/test ' , function (req, res< Span class= "pun" >) { Console. (req. Query. Name Console. (req. Query. Tel});
If it is through the form and is using the POST method:
<form Action='/test ' Method=' Post '> <input Type=' Text ' Name=' Name ' Value=' Fred '> <input type< Span class= "pun" >= ' text ' name= ' tel ' value=> <inputtype= ' submit ' value< Span class= "pun" >= ' Submit ' > </form >app.post ('/test ', function (req, res) {Console.log (req.query.id); Console.log (Req.body.name); Console.log (Req.body.tel);
It is also possible to Query the Strings and POST method forms simultaneously using:
<form Action='/test?id=3 ' Method=' Post '> <input Type=' Text ' Name=' Name ' Value=' Fred '> <input type< Span class= "pun" >= ' text ' name= ' tel ' value=> <inputtype= ' submit ' value< Span class= "pun" >= ' Submit ' > </form >app.post ('/test ', function (req, res) {Console.log (req.query.id); Console.log (Req.body.name); Console.log (Req.body.tel);
And there's another way to do that is to pass the parameters to the Server, that is, using the path, you can use the HTTP Routing of the Web Server to parse, often see the various kinds of web Framework. This is not a standardized practice, it is an extension of the HTTP Routing.
GET/Hello/Fred/0926xxx572App.get('/hello/:name/:tel ', function(req, res) { console . Log(req. params. Name); console. Log(req. params. Tel); });
Using NodeJS + Express to take value from Get/post Request-excerpt from the network