问题:使用nodejs请求flask出现400错误,如下图:
vscode:nodejs
pycharm:python-flask
nodejs代码
const https = require('https')
const option = {
hostname: '127.0.0.1',
port: 5000,
path: '/manage/mall/pictures/name',
method: 'GET',
headers: {
'Content-Type': 'application/json; charset=utf-8',
}
}
const req = https.request(option, res => {
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.end()
问题原因
flask没有添加SSL证书,所以将请求方式从https改为http即可解决问题
改正后的nodejs代码
const http = require('http')
const option = {
hostname: '127.0.0.1',
port: 5000,
path: '/manage/mall/pictures/name',
method: 'GET',
headers: {
'Content-Type': 'application/json; charset=utf-8',
}
}
const req = http.request(option, res => {
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.end()