javascript - Why do many projects serialize the data in the request body before sending a post request?
天蓬老师
天蓬老师 2017-06-15 09:23:20
0
2
900

I found that many projects use "querystring parsing and stringifying library" to serialize the data to be transmitted in post requests, such as qs.

//POST传参序列化(添加请求拦截器)
axios.interceptors.request.use((config) => {
    //在发送请求之前做某件事
    if(config.method  === 'post'){
        config.data = qs.stringify(config.data);
    }
    return config;
},(error) =>{
     _.toast("错误的传参", 'fail');
    return Promise.reject(error);
});

There is a sentence in the introduction in qs: "A querystring parsing and stringifying library with some added security." May I ask where the safety is reflected?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
伊谢尔伦

Look at the test cases of qs and you will know https://github.com/ljharb/qs/...

The security value is that the data you construct is legal.

曾经蜡笔没有小新

The comment was written in the wrong place qs Is this library mainly used to detect whether the data is legal? Because if I used jQuery and axios before, I could still send ajax requests even if I didn’t add the qs library.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!