首页 > 解决方案 > 如何在后请求中将json数据发送到javascript中的url

问题描述

我想发送这样的数据

{"update_id":121631120,"message":{"message_id":1,"from":{"id":"TGID","is_bot":false,"first_name":"ELBARON @LxEEE","username":"USERNAME","language_code":"en"},"chat":{"id":"TGID","first_name":"ELBARON @LxEEE","username":"USERNAME","type":"private"},"date":1594553383,"text":"TEXT"}}

到这个网址

http://hfkm.ga/market/usersbothf/491856302/suc.php

使用 javascript,但我找不到帮助。

标签: javascriptjson

解决方案


Axios 可用于发送 HTTP 请求,例如 fetch api。安装 axios 使用:(npm install axios 假设安装了 nodejs)

或者

您可以使用 CDN:(将其<script src="https://unpkg.com/axios/dist/axios.min.js"></script>粘贴到您的 index.html 中)

axios({
    method: 'post',
    url: '/login',
    data: {
        update_id: 121631120,
        message: {
            message_id: 1,
            from: {like so...}
        }
    }
})
.then((response) => {
        console.log(response);
    }, (error) => {
        console.log(error);
    }

更多详情:https ://blog.logrocket.com/how-to-make-http-requests-like-a-pro-with-axios/


推荐阅读