我发送出去的数据发现后台接收不到,查找了一下原因,发现需要form-data的数据后台才可以获取到。于是改成了form-data格式,成功了,后台获取到数据了,有点小激动,但是随即发现发送的数据格式出现了问题,发送的本来是json,但是到了后台那边变了个样,去axios的官方文档上面查找原因,发现需要form-data的数据无法发送json格式的,需要对json进行qs.stringify()才可以。

import qs from 'qs'
config.data = qs.stringify(config.data);

qs.stringify()将对象 序列化成URL的形式这样后端就能直接解析数据
(json格式)—qs.stringify()— (application/x-www-form-urlencoded格式)

请求头转换
const server = axios.create({
baseURL: ‘http://192.168.0.177:3030/’,
timeout: 5000,
headers: {
//为了不进行预处理请求需要用这种格式的数据
‘content-type’: ‘application/x-www-form-urlencoded’
}
})

application/x-www-form-urlencoded是字符串类型的数据
application/json是对象类型的数据

GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
2134cb94 * change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance * fix ci_static_analysis_clang (ci_clang_tidy) * change NLOHMANN_JSON_FROM_WITH_DEFAULT to let NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT work with an empty JSON instance 8 天前
6057b31d * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * Use ubuntu-latest image to run Valgrind (#4575) * :wrench: use Clang image to run valgrind * :wrench: use Clang image to run valgrind * :wrench: use Clang image to run valgrind * :wrench: use Ubuntu image to run valgrind * Use Clang image to run iwyu (#4574) * :wrench: use Clang image to run iwyu * :wrench: use Clang image to run iwyu * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :wrench: overwork astyle call * :art: format code * :hammer: clean up 10 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐