axios 使用 json 数据发布请求 [英] axios post request with json data

查看:76
本文介绍了axios 使用 json 数据发布请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Axios JS 库来发送 post json 请求.但我没有在服务器上收到任何东西.这是我的代码

I am using Axios JS library for sending post json request. but I am not receiving anything at the server. Here is my code

const dt = JSON.stringify({"data":{"value":"gdfg1df2g2121dgfdg"}});
const request = axios.post(url, {dt});

我需要发送json格式的原始正文.

推荐答案

默认情况下,axios 使用 Json 来发布数据,因此您无需对数据进行字符串化.问题可能是你正在这样做.您可以尝试在没有它的情况下进行发布并检查它是否有效吗?此外,除非这是服务器中对象的格式,否则您不需要花括号来包装数据.否则,您能否提供有关请求正文的信息,以便我了解更多上下文?您可以使用网络选项卡在 chrome 开发工具中检查这一点

By default axios uses Json for posting data so you don't need to stringify your data. The problem could be that you're doing that. Could you try doing the post without it and check if it works? Also you don't need the curly braces to wrap your data unless that's the format of the object in your server. Otherwise could you give me information about how the body of the request looks like so I have more context? You can check that in chrome dev tools using the network tab

这篇关于axios 使用 json 数据发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆