简体   繁体   English

如何在后请求中将 json 数据发送到 javascript 中的 url

[英]How to send json data in post-request to url in javascript

i want to send data like this我想发送这样的数据

{"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"}}

to this url到这个 url

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

using javascript, but i can't find somthing help.使用 javascript,但我找不到帮助。

Axios can be used to send HTTP requests like the fetch api. Axios 可用于发送 HTTP 请求,例如获取 api。 For installing axios use: npm install axios (assuming nodejs is installed)安装 axios 使用: npm install axios (假设安装了nodejs)

OR或者

you can use the CDN: <script src="https://unpkg.com/axios/dist/axios.min.js"></script> (paste this in your index.html)您可以使用 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);
    }

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM