javascript - 如何在后请求中将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,但我找不到帮助。
解决方案
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/
推荐阅读
- docker - Docker-compose - memsql 容器 - 后端连接问题
- azure-devops - 创建与 azure 资源管理器的服务连接时出错:azure 管道
- javascript - 单个客户端中的 SockJS 多个连接
- javascript - 如何在 React 中显示页面之前加载所有图像?
- javascript - 初学者 Js:REST API 在成功调用时返回“未定义”
- git - 如何找到指定分支的父分支?
- python - Lambda 函数返回 Failed loading language 'eng' Tesseract 无法加载任何语言!无法初始化 tesseract
- kubernetes - 谷歌云存储作为 Kubernetes 状态集的卷
- flutter - Flutter 需要一个条形图,我可以在其中单击条形图以打开包含相关信息的新页面
- html - 具有不同 Web 链接的弹出式模态 iframe