Parameter passing method of get request and post request

1. Advantages and disadvantages of GET and POST parameter transfer methods

        1. post is more secure (it will not be used as part of the url, will not be cached, and will be saved in server logs and browser browsing records)

        2. The amount of data sent by post is larger (get has a url length limit)

        3. post can send more data types (get can only send ASCII characters)

        4. post is slower than get

        5. Post is a request to submit data to the server, and get is a request to send data to the server.

        5. Post is a request to submit data to the server, and get is a request to send data to the server.

        7. The post request contains more request headers

        8. Post will send the request header to the server for confirmation before actually accepting the data, and then actually send the data

2. The request process of GET and POST parameter transfer methods

The process of post request:

1. The browser requests a tcp connection (the first handshake)
2. The server agrees to make a tcp connection (the second handshake)
3. The browser confirms and sends the post request header (the third handshake, this message is relatively small, so http will send data for the first time at this time)
4. The server returns a 100 continue response
5. The browser starts sending data
6. The server returns a 200 ok response


The process of get request

1. The browser requests a tcp connection (the first handshake)
2. The server agrees to make a tcp connection (the second handshake)
3. The browser confirms and sends the get request header and data (the third handshake, this message is relatively small , so http
will send the first data at this time)
4. The server returns a 200 ok response.

3. axios

       1. Axios installation

$  npm install axios   // 使用npm
$  bower install axios   // 使用bower
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>   // 通过cdn直接调用

        2. Axios reference

import axios from 'axios';

        3. Get parameter transfer method template

                The first type of parameter (the parameter is on the url)

axios.get('/adate?id=123').then(res => {
    console.log(res);
})

                The second type of parameter passing (passing parameters through the param option)

axios.get('/adate?id=123',{
    params: {
        id: 1
    }
}).then(res => {
    console.log(res);
})

        4. post parameter passing module

axios.post('/api/axios', {
    uname: 'lisi',
    pwd: 123
}).then(ret => {
    console.log(ret.data)
})

Guess you like

Origin blog.csdn.net/qq_52421092/article/details/125745265