带有json数据的axios发布请求 [英] axios post request with json data
问题描述
我正在使用Axios JS库发送后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格式发送 post raw body .
I need to send post raw body in json format.
推荐答案
默认情况下, 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
这篇关于带有json数据的axios发布请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!