当前位置:网站首页>electron net 如何发送 post 请求
electron net 如何发送 post 请求
2022-04-21 12:12:00 【十月ooOO】
electron net 如何发送 post 请求
用 electron 的 net 发送 post 请求时, 我不确定的是发送方式该如何设置,查了半天,也试了半天,总结出来了
请求方式
// 引入 net
const {
net } = require('electron')
let userInfo = {
email: kylebing@163.com,
password: '1234'
}
// 1. 新建 net.request 请求
const request = net.request({
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
url: 'http://localhost:3000/user/login'
})
// 2. 通过 request.write() 方法,发送的 post 请求数据需要先进行序列化,变成纯文本的形式
request.write(JSON.stringify(userInfo))
// 3. 处理返回结果
request.on('response', response => {
response.on('data', res => {
// res 是 Buffer 数据
// 通过 toString() 可以转为 String
// 详见: https://blog.csdn.net/KimBing/article/details/124299412
let data = JSON.parse(res.toString())
})
response.on('end', () => {
})
})
// 4. 记得关闭请求
request.end()
服务器接收的数据是这样的,以 nodejs 的 express 为例,处于 req.body 中

版权声明
本文为[十月ooOO]所创,转载请带上原文链接,感谢
https://kylebing.blog.csdn.net/article/details/124300102
边栏推荐
- Notepad++怎么复制多行黏贴到对应位置
- Cultdao, a decentralized VC platform, launched a vote on the betamars project, which is currently in progress
- 【软件测试系列十二】《压力测试报告模板》
- 《深度学习》学习笔记(六)
- 《深度学习》学习笔记(七)
- There is no market for virtual currency. Why can there be no small temptation for some people?
- vscode 经常弹出:尝试在目标目录创建文件时发生一个错误 重试 跳过这个文件 关闭安装程序
- [Software Testing Series IV] "test points to be paid attention to in software testing"
- Title record of TIANTI competition (II)
- Yyds dry goods inventory a common error in a web crawler
猜你喜欢

Kubernetes 服务发现 监控APIServer

php如何判断指定日期是不是前一天

Yyds dry goods inventory a common error in a web crawler

Kubernetes service discovery monitoring apiserver

每日AI前沿术语:主动学习(Active Learning)

NoSuchBeanDefinitionException - not resolved currently

World Reading Day | recommended books list of database classic books (free message at the end of the text)

Integration announcement keyfi is now online moonbeam
![[BSidesCF 2019]Kookie](/img/85/e97fe5ec5fa94bc007af56c7098b11.png)
[BSidesCF 2019]Kookie

教你轻松解决CSRF跨站请求伪造攻击
随机推荐
爱可可AI前沿推介 (4.21)
What's the use of the enterprise's official website? Do you have to build an official website?
Sublime theme colors
Yyds dry goods inventory a common error in a web crawler
[software test series vi] software system test scheme
[Software Test Series VII] software test plan
【软件测试系列九】《压力测试申请需提供事项说明》
数据库,把另一张表某字段数据添加到另一个表中,同时加入的时候加入自己需要的数据
【软件测试系列五】《软件测试申请表》
精彩联动!OpenMLDB Pulsar Connector原理和实操
Release announcement of HMS core version 6.4.0
Operation of WinForm GridView
Oracle provides superior database performance and scale through exadata cloud infrastructure x9m
[data visualization application] draw bivariate mapping map (with R language code)
[software test series 8] software project test report
[dark horse morning post] Tao Hong paid 260 million dividends from Zhangting MLM company in three years; Yiling pharmaceutical replied to Lianhua Qingwen dispute: the case has been reported; Tencent v
Offline RL Series 4: analysis of the influence of sample complexity on model convergence
One minute teaches you to use yolov5 to train your dataset and test it
[flutter topic] 89 graphic basic overlay suspension novice guide # yyds dry goods inventory #
【数据可视化应用】绘制双变量映射地图(附R语言代码)